﻿Imports System.Globalization

Partial Public Class SHIP_LD_PERFORMANCE_CONTROL
    Inherits System.Web.UI.Page

    Dim clsGet As New ClassFunctionGetData()
    Dim clsFc As New ClassFunction
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim lbPage As Label = CType(Master.FindControl("lbPage"), Label)
            lbPage.Text = "SHIP LOADING/UNLOADING PERFORMANCE CONTROL"

            txtPlanBerthFrom.Text = Date.Now.AddDays(-6).ToString("dd MMM yyyy", New CultureInfo("en-US"))
            txtPlanBerthTo.Text = Date.Now.ToString("dd MMM yyyy", New CultureInfo("en-US"))

            LoadBOoking()
            ViewState("Load") = "Not"
            Timer1_Tick(sender, e)
            Session("Delay") = Nothing
            Session("TugBeforeLoading") = Nothing
            Session("TugAfterLoading") = Nothing
            txtBookingVPS.Attributes.Add("onkeypress", "return clickButton(event,'" + btnSearchVPS.ClientID + "')")
            txtShipVPS.Attributes.Add("onkeypress", "return clickButton(event,'" + btnSearchVPS.ClientID + "')")
            txtProductSearch.Attributes.Add("onkeypress", "return clickButton(event,'" + btnSearchVPS.ClientID + "')")
        End If
    End Sub

    Private Sub LoadBOoking()
        PanelBookingItem.Visible = True
        PanelShipLoading.Visible = False
        Dim ds As DataSet
        Dim DateFrom As String = ""
        Dim DateTo As String = ""
        If (txtDateSearch.Text.Trim <> "") And (txtDateToSearch.Text.Trim() <> "") Then
            DateFrom = txtDateSearch.Text.Split(" ")(2) & CDate(ClassFunctionGetData.CDateT(txtDateSearch.Text)).ToString("MMdd")
            DateTo = txtDateToSearch.Text.Split(" ")(2) & CDate(ClassFunctionGetData.CDateT(txtDateToSearch.Text)).ToString("MMdd")
        End If
        If (ddlStatusVPS.SelectedValue = "C") Then
            ds = clsGet.Get_Booking("", "", "", "'CV','CC','CM','CR','CA'", True, "L", txtShipVPS.Text, "", "", txtBookingVPS.Text, ddlDestinationSearch.SelectedValue, DateFrom, DateTo, txtProductSearch.Text)
        ElseIf (ddlStatusVPS.SelectedValue = "J") Then
            ds = clsGet.Get_Booking("", "", "", "'FN','OA'", True, "L", txtShipVPS.Text, "", "", txtBookingVPS.Text, ddlDestinationSearch.SelectedValue, DateFrom, DateTo, txtProductSearch.Text)
        ElseIf (ddlStatusVPS.SelectedValue = "A") Then
            ds = clsGet.Get_Booking("", "", "", "'MO'", True, "L", txtShipVPS.Text, "", "", txtBookingVPS.Text, ddlDestinationSearch.SelectedValue, DateFrom, DateTo, txtProductSearch.Text)
        Else
            ds = clsGet.Get_Booking("", "", "", "'MO'", True, "L", txtShipVPS.Text, "", "", txtBookingVPS.Text, ddlDestinationSearch.SelectedValue, DateFrom, DateTo, txtProductSearch.Text)


            Dim dsTemp As DataSet = ds.Copy
            Dim count As Integer = 0
            For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                Dim dtStatus As DataTable = clsGet.Get_Load_Unload_Vessel(ds.Tables(0).Rows(i).Item("Booking_no"))
                If (ddlStatusVPS.SelectedValue = "L") Then
                    If (dtStatus.Rows.Count > 0) Then
                        If ((dtStatus.Rows(0).Item("Status") & "" = "C") Or (dtStatus.Rows(0).Item("Status") & "" = "A") Or (dtStatus.Rows(0).Item("Status") & "" = "S")) Then
                            dsTemp.Tables(0).Rows(i - count).Delete()
                            dsTemp.AcceptChanges()
                            count += 1
                        End If
                    End If
                ElseIf (ddlStatusVPS.SelectedValue = "U") Then
                    If (dtStatus.Rows.Count > 0) Then
                        If (Not (dtStatus.Rows(0).Item("Status") & "" = "S")) Then
                            dsTemp.Tables(0).Rows(i - count).Delete()
                            dsTemp.AcceptChanges()
                            count += 1
                        End If
                    Else
                        dsTemp.Tables(0).Rows(i - count).Delete()
                        dsTemp.AcceptChanges()
                        count += 1
                    End If
                ElseIf (ddlStatusVPS.SelectedValue = "T") Then
                    dtStatus = clsGet.Get_Booking_LogSheet_Out(ds.Tables(0).Rows(i).Item("Booking_no"))
                    If (dtStatus.Rows.Count > 0) Then
                        If (dtStatus.Rows(0).Item("Status") & "" = "A") Then
                            dsTemp.Tables(0).Rows(i - count).Delete()
                            dsTemp.AcceptChanges()
                            count += 1
                        End If
                    Else
                        dsTemp.Tables(0).Rows(i - count).Delete()
                        dsTemp.AcceptChanges()
                        count += 1
                    End If
                Else 'Section
                    If (dtStatus.Rows.Count > 0) Then
                        If (Not (dtStatus.Rows(0).Item("Status") & "" = "C")) Then
                            dsTemp.Tables(0).Rows(i - count).Delete()
                            dsTemp.AcceptChanges()
                            count += 1
                        End If
                    Else
                        dsTemp.Tables(0).Rows(i - count).Delete()
                        dsTemp.AcceptChanges()
                        count += 1
                    End If
                End If
            Next
            ds = dsTemp
            ds.AcceptChanges()

        End If

        If (txtPlanBerthFrom.Text <> "") And (txtPlanBerthTo.Text <> "") Then
            Dim c As Integer = 0
            Dim dtTemp As DataTable = ds.Tables(0).Copy
            For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                Dim dtLogin As DataTable = clsGet.Get_BookingWharf(ds.Tables(0).Rows(i).Item("Booking_no"))
                Try
                    If (CDate(ClassFunctionGetData.CDateT(dtLogin.Rows(0).Item("Date_From"))) > CDate(ClassFunctionGetData.CDateT(txtPlanBerthFrom.Text))) Then
                        If (CDate(ClassFunctionGetData.CDateT(dtLogin.Rows(0).Item("Date_From"))) > CDate(ClassFunctionGetData.CDateT(txtPlanBerthTo.Text))) Then
                            dtTemp.Rows(i - c).Delete()
                            dtTemp.AcceptChanges()
                            c += 1
                        End If
                    ElseIf (CDate(ClassFunctionGetData.CDateT(dtLogin.Rows(0).Item("Date_To"))) < CDate(ClassFunctionGetData.CDateT(txtPlanBerthFrom.Text))) Then
                        dtTemp.Rows(i - c).Delete()
                        dtTemp.AcceptChanges()
                        c += 1
                    End If
                Catch ex As Exception
                    dtTemp.Rows(i - c).Delete()
                    dtTemp.AcceptChanges()
                    c += 1
                End Try
            Next
            ds.Tables.Clear()
            ds.Tables.Add(dtTemp.Copy)
            ds.AcceptChanges()
        End If

        If (ddlProductLD.SelectedValue <> "A") Then
            Dim dsTemp As DataSet = ds.Copy
            Dim count As Integer = 0
            For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                Dim dt As DataTable = clsGet.Get_Booking_Product(ds.Tables(0).Rows(i).Item("Booking_no"))
                If (dt.Rows.Count > 0) Then
                    If (dt.Rows(0).Item("Product_Event") & "" <> ddlProductLD.SelectedValue) Then
                        dsTemp.Tables(0).Rows(i - count).Delete()
                        dsTemp.AcceptChanges()
                        count += 1
                    End If
                Else
                    dsTemp.Tables(0).Rows(i - count).Delete()
                    dsTemp.AcceptChanges()
                    count += 1
                End If
            Next
            ds = dsTemp
        End If
        ds.AcceptChanges()
        If (ds.Tables(0).Rows.Count > 0) Then
            ViewState("Operation") = ds
            gridItem.DataSource = ViewState("Operation")
            gridItem.DataBind()
            lbAlert.Text = ""
        Else
            gridItem.DataSource = Nothing
            gridItem.DataBind()
            lbAlert.Text = "ไม่พบรายการ Booking"
        End If
    End Sub

    Public Sub Paginate(ByVal sender As Object, ByVal e As CommandEventArgs)
        Dim CurrentIndex As Integer = gridItem.PageIndex
        Select Case e.CommandArgument.ToString().ToLower()
            Case "first"
                gridItem.PageIndex = 0
            Case "prev"
                If (gridItem.PageIndex <> 0) Then
                    gridItem.PageIndex = CurrentIndex - 1
                End If
            Case "next"
                If (gridItem.PageIndex <> gridItem.PageCount) Then
                    gridItem.PageIndex = CurrentIndex + 1
                End If
            Case "last"
                gridItem.PageIndex = gridItem.PageCount
        End Select
        gridItem.DataSource = ViewState("Operation")
        gridItem.DataBind()
        ViewState("Load") = "Not"
        Timer1_Tick(sender, e)
    End Sub

    Protected Sub ddlPage_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim Page As GridViewRow = gridItem.BottomPagerRow
        Dim ddlPage As DropDownList = CType(Page.Cells(0).FindControl("ddlPage"), DropDownList)
        gridItem.PageIndex = ddlPage.SelectedIndex
        gridItem.DataSource = ViewState("Operation")
        gridItem.DataBind()
        ViewState("Load") = "Not"
        Timer1_Tick(sender, e)
    End Sub

    Private Sub gridItem_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridItem.RowCommand
        Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
        If (gridItem.PageIndex <> 0) Then
            Index = Index Mod (gridItem.PageIndex * 10)
        End If
        If e.CommandName = "Edit" Then
            ViewState("StandardTimeProductLast") = ""
            ViewState("StandardTimeProductLastDate") = ""
            ViewState("StopActual") = ""
            ViewState("EditBooking") = gridItem.DataKeys(Index).Values("Booking_no")
            lbBooking_no.Text = gridItem.DataKeys(Index).Values("Booking_no")
            lbVessel.Text = gridItem.DataKeys(Index).Values("Vehicle_Text")
            lbVessel_Name.Text = gridItem.DataKeys(Index).Values("Vehicle_Text")
            If (gridItem.DataKeys(Index).Values("Status") & "" = "OA") Then
                btnSave.Visible = False
            Else
                btnSave.Visible = True
            End If

            Dim dt As DataTable = clsGet.Get_Booking_LogSheet_In(ViewState("EditBooking"))
            If (dt.Rows.Count = 1) Then
                If (dt.Rows(0).Item("Berthing_TimeTo") & "" <> "") Then
                    lbarrived.Text = ConvertDate(dt.Rows(0).Item("Anchor_Date")) & " " & dt.Rows(0).Item("Anchor_Time")
                    lbNOR.Text = ConvertDate(dt.Rows(0).Item("Anchor_Date")) & " " & dt.Rows(0).Item("Anchor_Time")
                    lbPOB.Text = ConvertDate(dt.Rows(0).Item("POB_Date")) & " " & dt.Rows(0).Item("POB_Time")
                    lbFirstling.Text = ConvertDate(dt.Rows(0).Item("Berthing_Date")) & " " & dt.Rows(0).Item("Berthing_TimeFrom")
                    Try
                        Dim TimeFrom As String = dt.Rows(0).Item("Berthing_TimeFrom").ToString.Replace(":", "")
                        Dim TimeTo As String = dt.Rows(0).Item("Berthing_TimeTo").ToString.Replace(":", "")
                        If (CDbl(TimeFrom) > CDbl(TimeTo)) Then
                            lbBerthedStandardDate.Text = ConvertDate(CDate(ClassFunctionGetData.CDateT(dt.Rows(0).Item("Berthing_Date"))).AddDays(1))
                            lbBerthedStandard.Text = dt.Rows(0).Item("Berthing_TimeTo")
                            lbBerthedDate.Text = ConvertDate(CDate(ClassFunctionGetData.CDateT(dt.Rows(0).Item("Berthing_Date"))).AddDays(1))
                            lbBerthed.Text = dt.Rows(0).Item("Berthing_TimeTo")
                            lbAccept.Text = ConvertDate(CDate(ClassFunctionGetData.CDateT(dt.Rows(0).Item("Berthing_Date"))).AddDays(1)) & " " & dt.Rows(0).Item("Berthing_TimeTo")
                        Else
                            lbBerthedStandardDate.Text = ConvertDate(dt.Rows(0).Item("Berthing_Date"))
                            lbBerthedStandard.Text = dt.Rows(0).Item("Berthing_TimeTo")
                            lbBerthedDate.Text = ConvertDate(dt.Rows(0).Item("Berthing_Date"))
                            lbBerthed.Text = dt.Rows(0).Item("Berthing_TimeTo")
                            lbAccept.Text = ConvertDate(dt.Rows(0).Item("Berthing_Date")) & " " & dt.Rows(0).Item("Berthing_TimeTo")
                        End If
                    Catch ex As Exception
                        lbBerthedStandardDate.Text = ConvertDate(dt.Rows(0).Item("Berthing_Date"))
                        lbBerthedStandard.Text = dt.Rows(0).Item("Berthing_TimeTo")
                        lbBerthedDate.Text = ConvertDate(dt.Rows(0).Item("Berthing_Date"))
                        lbBerthed.Text = dt.Rows(0).Item("Berthing_TimeTo")
                        lbAccept.Text = ConvertDate(dt.Rows(0).Item("Berthing_Date")) & " " & dt.Rows(0).Item("Berthing_TimeTo")
                    End Try

                    Try
                        txtNORTender.Text = CDate(ClassFunctionGetData.CDateT(dt.Rows(0).Item("Anchor_Date"))).ToString("dd/MM/yy")
                    Catch ex As Exception
                        txtNORTender.Text = ""
                    End Try
                    txtNORTenderTime.Text = dt.Rows(0).Item("Anchor_Time") & ""
                Else
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เรือยังไม่ได้เข้าเทียบท่า หรือ PTMM ไม่ได้ทำการระบข้อมูล All fast!!');", True)
                    LoadBOoking()
                    ViewState("Load") = "Not"
                    Timer1_Tick(sender, e)
                    Exit Sub
                End If
            Else
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เรือยังไม่ได้เข้าเทียบท่า!!');", True)
                LoadBOoking()
                ViewState("Load") = "Not"
                Timer1_Tick(sender, e)
                Exit Sub
            End If

            dt = clsGet.Get_Booking_ProductOperation(ViewState("EditBooking"))
            If (dt.Rows.Count > 0) Then
                For Each dr As DataRow In dt.Rows
                    If (dr.Item("Product_Index") & "" = "") Then
                        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('สินค้ายังไม่ได้ถูกทำการระบุรายละเอียดการขนถ่าย!!');", True)
                        LoadBOoking()
                        ViewState("Load") = "Not"
                        Timer1_Tick(sender, e)
                        Exit Sub
                    End If
                Next
            Else
                dt = clsGet.Get_Booking_Product(ViewState("EditBooking"))
                If (dt.Rows.Count > 0) Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('สินค้ายังไม่ได้ถูกทำการระบุรายละเอียดการขนถ่าย!!');", True)
                    LoadBOoking()
                    ViewState("Load") = "Not"
                    Timer1_Tick(sender, e)
                    Exit Sub
                End If
            End If
            Dim Product_name As String = ""
            For Each dp As DataRow In dt.Rows
                If Product_name = "" Then
                    Product_name = dp.Item("Product_name")
                Else
                    Product_name &= "," & dp.Item("Product_name")
                End If
            Next
            lbProduct.Text = Product_name
            lbCommodity.Text = Product_name
            ViewState("Load") = ""
            gridProduct.DataSource = dt
            gridProduct.DataBind()

            If (ViewState("Load") = "Not") Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ไม่พบข้อมูล StandardTime กรุณาทำการตรวจสอบ Shore');", True)
                LoadBOoking()
                Timer1_Tick(sender, e)
                Exit Sub
            End If
            If (dt.Rows.Count = 0) Then
                lbBunkerStandardDate.Text = lbBerthedStandardDate.Text
                lbBunkerStandard.Text = lbBerthedStandard.Text
                lbDepartStandardDate.Text = lbBunkerStandardDate.Text
                lbDepartStandard.Text = lbBunkerStandard.Text
            Else
                Dim lbStopStandardDate As Label = CType(gridProduct.Rows(gridProduct.Rows.Count - 1).FindControl("lbStopStandardDate"), Label)
                Dim lbStopStandard As Label = CType(gridProduct.Rows(gridProduct.Rows.Count - 1).FindControl("lbStopStandard"), Label)
                lbBunkerStandardDate.Text = lbStopStandardDate.Text
                lbBunkerStandard.Text = lbStopStandard.Text
                lbDepartStandardDate.Text = lbBunkerStandardDate.Text
                lbDepartStandard.Text = lbBunkerStandard.Text
            End If
            Dim dtStock As DataTable = clsGet.Get_Load_Unload_Addition_Stock(ViewState("EditBooking")).Tables(0)
            If (dtStock.Rows.Count < 1) Then
                For i As Integer = 0 To gridProduct.Rows.Count - 1
                    Dim dtUse As DataTable = clsGet.Check_ForUSE_Stock(gridProduct.DataKeys(i).Values("Product_no"))
                    If (dtUse.Rows.Count > 0) Then
                        Dim lbTargetQuatity As Label = CType(gridProduct.Rows(i).FindControl("lbTargetQuatity"), Label)
                        Dim LD As String = gridProduct.DataKeys(i).Values("Product_Event")
                        Dim lbQuatity As TextBox
                        If (LD = "L") Then

                            'If (dt.Rows(0).Item("Unit") & "" = "M3") Then
                            lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLM3_Load"), TextBox)
                            'Else
                            '    lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLMT_Load"), TextBox)
                            'End If
                        Else
                            'If (dt.Rows(0).Item("Unit") & "" = "M3") Then
                            lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLFig"), TextBox)
                            'Else
                            '    lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLFigMT"), TextBox)
                            'End If
                        End If
                        Dim Value As String = ""
                        If (lbQuatity.Text = "") Then
                            Value = lbTargetQuatity.Text
                        Else
                            Value = lbQuatity.Text
                        End If
                        Dim Additive As Double = 0.0
                        For Each du As DataRow In dtUse.Rows
                            If (du.Item("Type_Additional") & "" <> "M") Then
                                Dim Count As String = (CDbl(du.Item("Color_Point")) * (CDbl(Value) * 1000)) \ 1000000
                                Dim drow As DataRow = dtStock.NewRow
                                drow.Item("Stock_Code") = du.Item("Stock_Code")
                                drow.Item("Grade") = du.Item("Grade")
                                drow.Item("Brand") = du.Item("Brand")
                                drow.Item("Count") = Count
                                drow.Item("Status") = "Y"
                                ' drow.Item("Remark") = du.Item("Remark")
                                If (du.Item("Type_Additional") & "" = "A") Then
                                    Additive = CDbl(Count)
                                End If
                                dtStock.Rows.Add(drow)
                                dtStock.AcceptChanges()
                            End If

                        Next
                        For Each du As DataRow In dtUse.Rows
                            If (du.Item("Type_Additional") & "" = "M") Then
                                Dim Count As String = (CDbl(du.Item("Color_Point")) * ((CDbl(Value) + Additive) * 1000)) \ 1000000
                                Dim drow As DataRow = dtStock.NewRow
                                drow.Item("Stock_Code") = du.Item("Stock_Code")
                                drow.Item("Grade") = du.Item("Grade")
                                drow.Item("Brand") = du.Item("Brand")
                                drow.Item("Count") = Count
                                drow.Item("Status") = "Y"
                                'drow.Item("Remark") = du.Item("Remark")
                                dtStock.Rows.Add(drow)
                                dtStock.AcceptChanges()
                            End If
                        Next
                    End If
                Next
            End If
            Session("_STOCK") = dtStock
            gridStock.DataSource = dtStock
            gridStock.DataBind()

            Dim dtDelay As DataTable = clsGet.Get_Load_Unload_Delay(ViewState("EditBooking"))
            If (dtDelay.Rows.Count = 0) Then
                dtDelay = CreateTabelDelay()
            End If

            Dim str As String = clsGet.Get_Wharf_Shifting(ViewState("EditBooking"))
            If (str <> "") Then
                Try
                    lbHShifting.Text = str.Split("-")(0) & " :"
                    lbShifting.Text = str.Split("-")(1)
                    rowShifting.Visible = True
                Catch ex As Exception
                    rowShifting.Visible = False
                End Try
            Else
                rowShifting.Visible = False
            End If

            dt = clsGet.Get_Load_Unload_Vessel(ViewState("EditBooking"))
            'Liquid
            If (dt.Rows.Count > 0) Then
                'ทำการ Bind ค่า
                txtThirdParty.Text = dt.Rows(0).Item("Third_Party") & ""
                txtConcern.Text = dt.Rows(0).Item("Concern") & ""
                txtTankFrom.Text = dt.Rows(0).Item("Tank_From") & ""
                txtTankTo.Text = dt.Rows(0).Item("Tank_To") & ""
                txtFigureFrom.Text = dt.Rows(0).Item("Figure") & ""
                txtLabFrom.Text = dt.Rows(0).Item("Lab") & ""
                txtSamplingFrom.Text = dt.Rows(0).Item("Sampling_From") & ""
                txtSamplingTo.Text = dt.Rows(0).Item("Sampling_To") & ""
                txtLabFrom.Text = dt.Rows(0).Item("Labafter") & ""
                txtTankafterFrom.Text = dt.Rows(0).Item("Tankafter_From") & ""
                txtTankafterTo.Text = dt.Rows(0).Item("Tankafter_To") & ""
                txtFigureafter.Text = dt.Rows(0).Item("Figureafter") & ""
                txtDocument.Text = dt.Rows(0).Item("Document_Time") & ""
                txtBunker.Text = dt.Rows(0).Item("Bunker_Point") & ""
                lbTruckTime.Text = dt.Rows(0).Item("Bunker_Time") & ""
                lbBunkerStandardDate.Text = dt.Rows(0).Item("Bunker_Standard_Date") & ""
                lbBunkerStandard.Text = dt.Rows(0).Item("Bunker_Standard_Time") & ""
                txtBunkerActualDate.Text = dt.Rows(0).Item("Bunker_Actual_Date") & ""
                txtBunkerActualTime.Text = dt.Rows(0).Item("Bunker_Actual_Time") & ""
                txtBunkerActualTimeTo.Text = dt.Rows(0).Item("Bunker_Actual_TimeTo") & ""
                lbDepartStandardDate.Text = dt.Rows(0).Item("Depart_Standard_Date") & ""
                lbDepartStandard.Text = dt.Rows(0).Item("Depart_Standard_Time") & ""
                txtDepartActualDate.Text = dt.Rows(0).Item("Depart_Actual_Date") & ""
                txtDepartAutualTime.Text = dt.Rows(0).Item("Depart_Actual_Time") & ""
                txtNORTender.Text = dt.Rows(0).Item("NOR_Date") & ""
                txtNORTenderTime.Text = dt.Rows(0).Item("NOR_Time") & ""

                If (dt.Rows(0).Item("Status") & "" = "C") Then
                    btnCheck.Visible = False
                    btnSend.Visible = False
                    If (Session("Role") = "00018") Then
                        btnApprove.Visible = True
                        btnReject.Visible = True
                        btnSave.Visible = True
                    Else
                        btnReject.Visible = False
                        btnApprove.Visible = False
                        btnSave.Visible = False
                    End If

                ElseIf (dt.Rows(0).Item("Status") & "" = "S") Then
                    btnApprove.Visible = False
                    btnSend.Visible = False
                    If (Session("Role") = "00018") Or (Session("Role") = "00017") Then
                        btnCheck.Visible = True
                        btnReject.Visible = True
                    Else
                        btnReject.Visible = False
                        btnSave.Visible = True
                        btnCheck.Visible = False
                    End If

                ElseIf (dt.Rows(0).Item("Status") & "" = "A") Then
                    gridStock.Columns(0).Visible = False
                    gridStock.Columns(4).Visible = True
                    btnCheck.Visible = False
                    btnApprove.Visible = False
                    btnSend.Visible = False
                    btnReject.Visible = False
                    If (Session("Role") = "00018") Then
                        btnSave.Visible = True
                    Else
                        btnSave.Visible = False
                    End If
                Else
                    btnSave.Visible = True
                    btnCheck.Visible = False
                    btnApprove.Visible = False
                    btnReject.Visible = False
                    btnSend.Visible = True
                End If

                If Not ((Session("Role") = "00011") Or (Session("Role") = "00017") Or (Session("Role") = "00018")) Then
                    btnSave.Visible = False
                    ' btnPrintShip.Visible = False
                    btnApprove.Visible = False
                    btnReject.Visible = False
                    btnSend.Visible = False
                    btnApprove.Visible = False
                End If

                dt = clsGet.Get_Action_Operation(ViewState("EditBooking"))
                Dim Status As String = ""
                For Each dx As DataRow In dt.Rows
                    If (Status = "") Then
                        Status = dx.Item("A_Action") & " : " & dx.Item("A_By") & " " & dx.Item("A_Date") & " " & dx.Item("A_Time") & " " & dx.Item("A_Description")
                    Else
                        Status &= "<br />" & dx.Item("A_Action") & " : " & dx.Item("A_By") & " " & dx.Item("A_Date") & " " & dx.Item("A_Time") & " " & dx.Item("A_Description")
                    End If
                Next
                LiStatus.Text = Status
            Else
                LiStatus.Text = ""
                txtThirdParty.Text = ""
                txtConcern.Text = ""
                txtTankFrom.Text = ""
                txtTankTo.Text = ""
                txtFigureFrom.Text = ""
                txtLabFrom.Text = ""
                txtSamplingFrom.Text = ""
                txtSamplingTo.Text = ""
                txtLabFrom.Text = ""
                txtTankafterFrom.Text = ""
                txtTankafterTo.Text = ""
                txtFigureafter.Text = ""
                txtDocument.Text = ""
                txtBunker.Text = ""
                lbTruckTime.Text = ""
                'lbBunkerStandardDate.Text = ""
                'lbBunkerStandard.Text = ""
                txtBunkerActualDate.Text = ""
                txtBunkerActualTime.Text = ""
                txtBunkerActualTimeTo.Text = ""
                'lbDepartStandardDate.Text = ""
                'lbDepartStandard.Text = ""
                txtDepartActualDate.Text = ""
                txtDepartAutualTime.Text = ""

                btnSave.Visible = True
                btnCheck.Visible = False
                btnApprove.Visible = False
                btnReject.Visible = False
                btnSend.Visible = True
            End If

            'Comment  ไว้ ต้องเปิดออก
            dt = clsGet.Get_Load_Unload_Addition(ViewState("EditBooking"))
            If (dt.Rows.Count > 0) Then

                'lbGreen.Text = dt.Rows(0).Item("Green")
                'lbRed.Text = dt.Rows(0).Item("Red")
                'lbYellow.Text = dt.Rows(0).Item("Yellow")
                'lbOrange.Text = dt.Rows(0).Item("Orange")
                txtWater.Text = dt.Rows(0).Item("Water")
                ' lbAdditive.Text = dt.Rows(0).Item("Additive")
                txtDisposal.Text = dt.Rows(0).Item("Disposal")
                txtBunker_FO.Text = dt.Rows(0).Item("Bunker_FO")
                txtBunker_DO.Text = dt.Rows(0).Item("Bunker_DO")
                ' lbMarker.Text = dt.Rows(0).Item("Marker")
                txtExcise.Text = dt.Rows(0).Item("Excise")
                txtNitrogen.Text = dt.Rows(0).Item("Nitrogen")
                txtElectic.Text = dt.Rows(0).Item("Electric")
            Else
                ' lbGreen.Text = "0"
                ' lbRed.Text = "0"
                ' lbYellow.Text = "0"
                '   lbOrange.Text = "0"
                txtWater.Text = "0"
                '  lbAdditive.Text = "0"
                txtDisposal.Text = "0"
                txtBunker_FO.Text = "0"
                txtBunker_DO.Text = "0"
                'lbMarker.Text = "0"
                txtExcise.Text = "0"
                txtNitrogen.Text = "0"
                txtElectic.Text = "0"
            End If


            'ยังไม่ทำการ BInd ค่ากรณีที่เคย save ไว้ ตอน BIne ที่Bind   TUg_Before , Tug_After ด้วย
            dt = clsGet.Get_Booking_LogSheet_Tug(ViewState("EditBooking"), "I", "")
            Dim Tug_Name As String = ""
            For Each dr As DataRow In dt.Rows
                If (dr.Item("Tug_Name") & "" <> "") Then
                    If (Tug_Name = "") Then
                        Tug_Name = dr.Item("Tug_Name")
                    Else
                        Tug_Name &= "," & dr.Item("Tug_Name")
                    End If
                End If
            Next
            lbTugBefore.Text = Tug_Name
            dt = clsGet.Get_Booking_LogSheet_Tug(ViewState("EditBooking"), "O", "")
            Tug_Name = ""
            For Each dr As DataRow In dt.Rows
                If (dr.Item("Tug_Name") & "" <> "") Then
                    If (Tug_Name = "") Then
                        Tug_Name = dr.Item("Tug_Name")
                    Else
                        Tug_Name &= "," & dr.Item("Tug_Name")
                    End If
                End If
            Next
            lbTugAfter.Text = Tug_Name

            Session("Delay") = dtDelay
            gridDelay.DataSource = dtDelay
            gridDelay.DataBind()


            PanelBookingItem.Visible = False
            PanelShipLoading.Visible = True

            dtDelay = clsGet.Get_CountVessel_Liquid(ViewState("EditBooking"))
            If (dtDelay.Rows.Count = 0) Then
                Insert_CountNumber()
            Else
                lbNo.Text = dtDelay.Rows(0).Item("Number") & "/" & dtDelay.Rows(0).Item("Month")
                lbNo2.Text = lbNo.Text
            End If
            GenDateLiteral()
            GetPTOL()
        ElseIf e.CommandName = "Detail" Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " document.getElementById('ctl00_contentplaceholder1_IframeDetailPopup').src = '../FormPopup/Detail_VesselBerth_Popup.aspx';", True)
            Session("Booking_no_Detail") = gridItem.DataKeys(Index).Values("Booking_no")
            ModalPopupExtender5.Show()
        End If
    End Sub

    Private Sub Insert_CountNumber()
        Dim conn As New System.Data.SqlClient.SqlConnection(connString)
        Dim clsDB As New ClassDatabase
        Dim clsFc As New ClassFunction
        Dim condition As Boolean = True
        Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
        Dim Number As String = clsGet.Get_CountVessel_LiquidNumber(Date.Now.Month, Date.Now.Year)
        Application.Lock()
        conn.Open()

        tran = clsDB.BeginTran(conn)
        If (clsFc.Insert_CountVessel_Liquid(ViewState("EditBooking"), Number, Date.Now.Month, Date.Now.Year, conn, tran) < 1) Then
            condition = False
        End If

        If (condition) Then
            clsDB.CommitTran(tran)
            lbNo.Text = Number & "/" & Date.Now.Month
            lbNo2.Text = lbNo.Text
            'ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('บันทึกข้อมูลเสร็จสมบูรณ์ !!');", True)
        Else
            clsDB.RollBackTran(tran)
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เกิดความผิดพลาดในการบันทึก');", True)
        End If
        Application.UnLock()
        conn.Dispose()
    End Sub

    Private Function ConvertDate(ByVal value As String) As String
        Try
            Dim NewValue As String = CDate(ClassFunctionGetData.CDateT(value)).ToString("dd/MM/yy")
            Return NewValue
        Catch ex As Exception
            Return value
        End Try
    End Function

    Private Sub gridItem_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridItem.RowCreated
        If e.Row.RowType = DataControlRowType.Header Then
            Dim Grid As GridView = CType(sender, GridView)
            e.Row.Cells.Clear()
            Dim GridRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
            Dim GridRow1 As GridViewRow = New GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert)

            Dim table As TableCell = New TableCell()
            table.Text = "BOOKING NO."
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.CssClass = "locked"
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "VESSEL NAME"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.CssClass = "locked"
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "STATUS"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "STATUS APPORVE"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "LAY CAN/LAY DAY"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "REQUIRE DATE/TIME"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "LAY TIME"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "ATTACHMENT"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "COMMODITY"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "QUANTITY"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "UNIT"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "BUYER"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)


            table = New TableCell()
            table.Text = "SELLER"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "APPROVE BY MKT"
            table.HorizontalAlign = HorizontalAlign.Center
            table.ColumnSpan = 5
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "APPROVE BY"
            table.HorizontalAlign = HorizontalAlign.Center
            table.ColumnSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "TARIFF"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "AGENT"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "WHARF"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "PLAN BERTH DATE"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "PLAN BERTH TIME"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "PLAN DEPART DATE"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "PLAN DEPART TIME"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "CONFIRM PLAN BERTH"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "REMAIN LAYTIME(ESTIMATE)"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = "REMARK"
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            table = New TableCell()
            table.Text = ""
            table.HorizontalAlign = HorizontalAlign.Center
            table.RowSpan = 2
            table.Wrap = True
            GridRow1.Cells.Add(table)

            Grid.Controls(0).Controls.AddAt(0, GridRow1)

            table = New TableCell()
            table.Text = "PRODUCT"
            table.HorizontalAlign = HorizontalAlign.Center
            table.Wrap = True
            GridRow.Cells.Add(table)

            table = New TableCell()
            table.Text = "CUSTOM"
            table.HorizontalAlign = HorizontalAlign.Center
            table.Wrap = True
            GridRow.Cells.Add(table)

            table = New TableCell()
            table.Text = "FINANCE"
            table.HorizontalAlign = HorizontalAlign.Center
            table.Wrap = True
            GridRow.Cells.Add(table)

            table = New TableCell()
            table.Text = "DEMURRAGE"
            table.HorizontalAlign = HorizontalAlign.Center
            table.Wrap = True
            GridRow.Cells.Add(table)

            table = New TableCell()
            table.Text = "TERM"
            table.HorizontalAlign = HorizontalAlign.Center
            table.Wrap = True
            GridRow.Cells.Add(table)

            table = New TableCell()
            table.Text = "PTMP"
            table.HorizontalAlign = HorizontalAlign.Center
            table.Wrap = True
            GridRow.Cells.Add(table)

            table = New TableCell()
            table.Text = "PTMI"
            table.HorizontalAlign = HorizontalAlign.Center
            table.Wrap = True
            GridRow.Cells.Add(table)

            Grid.Controls(0).Controls.AddAt(1, GridRow)
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If (ViewState("Load") & "" <> "Not") Then
            LoadBOoking()
        Else
            ViewState("Load") = ""
        End If
        For i As Integer = 0 To gridItem.Rows.Count - 1
            Dim dsBooking As DataSet = clsGet.Get_BookingOneRecord(gridItem.DataKeys(i).Values("Booking_no"))
            If (dsBooking.Tables(0).Rows(0).Item("Lay_Time") & "" <> "0") Then
                Dim dtLogIn As DataTable = clsGet.Get_Booking_LogSheet_In(gridItem.DataKeys(i).Values("Booking_no"))
                If Not (dtLogIn.Rows.Count = 0) Then
                    If Not (dtLogIn.Rows(0).Item("Berthing_Date") & "" = "") Or (dtLogIn.Rows(0).Item("Berthing_TimeTo") & "" = "") Then
                        If Not (dtLogIn.Rows(0).Item("POB_Date") & "" = "") Or (dtLogIn.Rows(0).Item("POB_Time") & "" = "") Then
                            Dim dtProduct As DataTable = clsGet.Get_Booking_Product(gridItem.DataKeys(i).Values("Booking_no"))
                            If Not (dtProduct.Rows.Count = 0) Then
                                If (dsBooking.Tables(0).Rows(0).Item("PORT") & "" = "L") Then
                                    Dim Product_no As String = ""
                                    Try
                                        Dim sort As Integer = 0
                                        For Each dr As DataRow In dtProduct.Rows
                                            If (CInt(dr.Item("Product_Index") & "") > sort) Then
                                                sort = CInt(dr.Item("Product_Index"))
                                                Product_no = dr.Item("Product_no")
                                            End If
                                        Next
                                    Catch ex As Exception

                                    End Try
                                    Dim dtLoad As DataTable = clsGet.Get_Load_Unload_Vessel(gridItem.DataKeys(i).Values("Booking_no"))
                                    Dim NOR As String = ""
                                    Dim NOR_Time As String = ""
                                    Dim POB As String = ""
                                    Dim POB_Time As String = ""
                                    If (dtLoad.Rows.Count > 0) Then
                                        If (dtLoad.Rows(0).Item("NOR_Date") & "" <> "") Then
                                            NOR = dtLoad.Rows(0).Item("NOR_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad.Rows(0).Item("NOR_Date").ToString.Substring(3, 2)) & " 20" & dtLoad.Rows(0).Item("NOR_Date").ToString.Substring(6, 2)
                                            NOR_Time = dtLoad.Rows(0).Item("NOR_Time") & ""
                                        Else
                                            NOR = dtLogIn.Rows(0).Item("NOR_Date") & ""
                                            NOR_Time = dtLogIn.Rows(0).Item("NOR_Time") & ""
                                        End If
                                    Else
                                        NOR = dtLogIn.Rows(0).Item("NOR_Date") & ""
                                        NOR_Time = dtLogIn.Rows(0).Item("NOR_Time") & ""
                                    End If
                                    If (dtLogIn.Rows(0).Item("POB_Date") & "" <> "") Then
                                        If (dtLogIn.Rows(0).Item("Up_Date") & "" <> "") Then
                                            If (CDate(ClassFunctionGetData.CDateT(dtLogIn.Rows(0).Item("POB_Date"))) < CDate(ClassFunctionGetData.CDateT(dtLogIn.Rows(0).Item("Up_Date")))) Then
                                                POB = dtLogIn.Rows(0).Item("Up_Date") & ""
                                                POB_Time = dtLogIn.Rows(0).Item("Up_Time") & ""
                                            ElseIf (CDate(ClassFunctionGetData.CDateT(dtLogIn.Rows(0).Item("POB_Date"))) = CDate(ClassFunctionGetData.CDateT(dtLogIn.Rows(0).Item("Up_Date")))) Then
                                                If (CInt(dtLogIn.Rows(0).Item("POB_Time").ToString().Split(":")(0)) < CInt(dtLogIn.Rows(0).Item("Up_Time").ToString().Split(":")(0))) Then
                                                    POB = dtLogIn.Rows(0).Item("Up_Date") & ""
                                                    POB_Time = dtLogIn.Rows(0).Item("Up_Time") & ""
                                                ElseIf (CInt(dtLogIn.Rows(0).Item("POB_Time").ToString().Split(":")(0)) = CInt(dtLogIn.Rows(0).Item("Up_Time").ToString().Split(":")(0))) Then
                                                    If (CInt(dtLogIn.Rows(0).Item("POB_Time").ToString().Split(":")(1)) < CInt(dtLogIn.Rows(0).Item("Up_Time").ToString().Split(":")(1))) Then
                                                        POB = dtLogIn.Rows(0).Item("Up_Date") & ""
                                                        POB_Time = dtLogIn.Rows(0).Item("Up_Time") & ""
                                                    Else
                                                        POB = dtLogIn.Rows(0).Item("POB_Date") & ""
                                                        POB_Time = dtLogIn.Rows(0).Item("POB_Time") & ""
                                                    End If
                                                Else
                                                    POB = dtLogIn.Rows(0).Item("POB_Date") & ""
                                                    POB_Time = dtLogIn.Rows(0).Item("POB_Time") & ""
                                                End If
                                            Else
                                                POB = dtLogIn.Rows(0).Item("POB_Date") & ""
                                                POB_Time = dtLogIn.Rows(0).Item("POB_Time") & ""
                                            End If
                                        Else
                                            POB = dtLogIn.Rows(0).Item("POB_Date") & ""
                                            POB_Time = dtLogIn.Rows(0).Item("POB_Time") & ""
                                        End If
                                    Else
                                        POB = dtLogIn.Rows(0).Item("Up_Date") & ""
                                        POB_Time = dtLogIn.Rows(0).Item("Up_Time") & ""
                                    End If

                                    dtLoad = clsGet.Get_Load_Unload_Product_PTOL(gridItem.DataKeys(i).Values("Booking_no"), Product_no, "")
                                    Dim Dis_Date As String = ""
                                    Dim Dis_Time As String = ""
                                    For Each dl As DataRow In dtLoad.Rows
                                        Try
                                            If (Dis_Date = "") Then
                                                Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                                Dis_Time = dl.Item("LU_Disconnect_To") & ""
                                            End If
                                            Dim _DD As String = Dis_Date.Substring(0, 2) & " " & GetNameMonth(Dis_Date.Substring(3, 2)) & " " & CInt("20" & Dis_Date.Substring(6, 2))
                                            Dim _D2 As String = dl.Item("LU_Disconnect_Date").Substring(0, 2) & " " & GetNameMonth(dl.Item("LU_Disconnect_Date").Substring(3, 2)) & " " & CInt("20" & dl.Item("LU_Disconnect_Date").Substring(6, 2))
                                            If (CDate(ClassFunctionGetData.CDateT(_DD)) < CDate(ClassFunctionGetData.CDateT(_D2))) Then
                                                Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                                Dis_Time = dl.Item("LU_Disconnect_To") & ""
                                            ElseIf (CDate(ClassFunctionGetData.CDateT(_DD)) = CDate(ClassFunctionGetData.CDateT(_D2))) Then
                                                If (CInt(Dis_Time.Split(":")(0)) < CInt(dl.Item("LU_Disconnect_To").ToString.Split(":")(0))) Then
                                                    Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                                    Dis_Time = dl.Item("LU_Disconnect_To") & ""
                                                ElseIf (CInt(Dis_Time.Split(":")(0)) = CInt(dl.Item("LU_Disconnect_To").ToString.Split(":")(0))) Then
                                                    Try
                                                        If (CInt(Dis_Time.Split(":")(1)) < CInt(dl.Item("LU_Disconnect_To").ToString.Split(":")(1))) Then
                                                            Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                                            Dis_Time = dl.Item("LU_Disconnect_To") & ""
                                                        End If
                                                    Catch ex As Exception

                                                    End Try
                                                End If
                                            End If
                                        Catch ex As Exception

                                        End Try

                                    Next
                                    Dim Berthing_Date As String = dtLogIn.Rows(0).Item("Berthing_Date")
                                    Try
                                        Try
                                            If (CInt(dtLogIn.Rows(0).Item("Berthing_TimeTo").ToString().Split(":")(0)) < CInt(dtLogIn.Rows(0).Item("Berthing_TimeFrom").ToString.Split(":")(0))) Then
                                                Berthing_Date = CDate(ClassFunctionGetData.CDateT(Berthing_Date)).AddDays(1).ToString("dd MMM", New CultureInfo("en-US")) & " " & Berthing_Date.Split(" ")(2)
                                            End If
                                        Catch ex As Exception

                                        End Try
                                    Catch ex As Exception

                                    End Try

                                    If (dtLoad.Rows.Count > 0) Then
                                        gridItem.Rows(i).Cells(29).Text = clsGet.ComputeRemainLaytime(Berthing_Date, dtLogIn.Rows(0).Item("Berthing_TimeTo"), dsBooking.Tables(0).Rows(0).Item("Lay_Time"), dsBooking.Tables(0).Rows(0).Item("Date_From"), dsBooking.Tables(0).Rows(0).Item("Date_To"), POB, POB_Time, Dis_Date & "", Dis_Time & "", NOR, NOR_Time)
                                    Else
                                        gridItem.Rows(i).Cells(29).Text = clsGet.ComputeRemainLaytime(Berthing_Date, dtLogIn.Rows(0).Item("Berthing_TimeTo"), dsBooking.Tables(0).Rows(0).Item("Lay_Time"), dsBooking.Tables(0).Rows(0).Item("Date_From"), dsBooking.Tables(0).Rows(0).Item("Date_To"), POB, POB_Time, "", "", NOR, NOR_Time)
                                    End If

                                Else
                                    Dim dtProductBulk As DataTable = clsGet.Get_Booking_Product(gridItem.DataKeys(i).Values("Booking_no"))
                                    If (dtProductBulk.Rows.Count > 0) Then
                                        Dim chkCoil As Boolean = False
                                        For Each dx As DataRow In dtProductBulk.Rows
                                            If (dx.Item("Group_no") & "" = "00007") Then
                                                chkCoil = True
                                                Exit For
                                            End If
                                        Next
                                        If (chkCoil) Then
                                            gridItem.Rows(i).Cells(29).Text = clsGet.ComputeRemainLaytimeBulk(dsBooking.Tables(0).Rows(0).Item("Lay_Time"), gridItem.DataKeys(i).Values("Booking_no"))
                                        End If
                                    End If
                                End If
                                If (gridItem.Rows(i).Cells(28).Text <> "") Then
                                    If (gridItem.Rows(i).Cells(29).Text.Substring(0, 1) = "-") Then
                                        gridItem.Rows(i).Cells(29).ForeColor = Drawing.Color.Red
                                    Else
                                        gridItem.Rows(i).Cells(29).ForeColor = Drawing.Color.Black
                                    End If
                                End If

                            End If
                        End If
                    End If
                End If
            End If
        Next
    End Sub

    Private Function GetNameMonth(ByVal Month As String) As String
        Try
            Select Case (CInt(Month).ToString("00"))
                Case "01"
                    Return "Jan"
                Case "02"
                    Return "Feb"
                Case "03"
                    Return "Mar"
                Case "04"
                    Return "Apr"
                Case "05"
                    Return "May"
                Case "06"
                    Return "Jun"
                Case "07"
                    Return "Jul"
                Case "08"
                    Return "Aug"
                Case "09"
                    Return "Sep"
                Case "10"
                    Return "Oct"
                Case "11"
                    Return "Nov"
                Case "12"
                    Return "Dec"
                Case Else
                    Return ""
            End Select
        Catch ex As Exception
            Return Month
        End Try

    End Function

    Private Sub btnReLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReLoad.Click
        gridItem.DataSource = ViewState("Operation")
        gridItem.DataBind()
        LoadBOoking()
        ViewState("Load") = "Not"
        Timer1_Tick(sender, e)
    End Sub

    Private Sub gridItem_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridItem.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim imgVPS As Image = CType(e.Row.FindControl("imgVPS"), Image)
            Dim imgMRI As Image = CType(e.Row.FindControl("imgMRI"), Image)
            Dim imgVPSComment As Image = CType(e.Row.FindControl("imgVPSComment"), Image)
            Dim imgMRIComment As Image = CType(e.Row.FindControl("imgMRIComment"), Image)
            Dim imgMKT As Image = CType(e.Row.FindControl("imgMKT"), Image)
            Dim imgProduct As Image = CType(e.Row.FindControl("imgProduct"), Image)
            Dim imgCustom As Image = CType(e.Row.FindControl("imgCustom"), Image)
            Dim imgFinance As Image = CType(e.Row.FindControl("imgFinance"), Image)
            Dim imgApprove As Image = CType(e.Row.FindControl("imgApprove"), Image)
            clsFc.GetImageStatus(imgVPS, imgMRI, imgMKT, gridItem.DataKeys(e.Row.RowIndex).Values("VPS_approve"), gridItem.DataKeys(e.Row.RowIndex).Values("MRI_approve"), gridItem.DataKeys(e.Row.RowIndex).Values("Marketing_approve"), gridItem.DataKeys(e.Row.RowIndex).Values("Status"))
            clsFc.GetImageStatusMKT(imgProduct, imgCustom, imgFinance, gridItem.DataKeys(e.Row.RowIndex).Values("MKT_Product"), gridItem.DataKeys(e.Row.RowIndex).Values("MKT_Custom"), gridItem.DataKeys(e.Row.RowIndex).Values("MKT_Finance"))

            If (gridItem.DataKeys(e.Row.RowIndex).Values("Payin") & "" = "0") Then
                Dim dt As DataTable = clsGet.Get_Booking_Gl_Account(gridItem.DataKeys(e.Row.RowIndex).Values("Booking_no"), gridItem.DataKeys(e.Row.RowIndex).Values("MAgent_no"))
                If (dt.Rows.Count > 0) Then
                    imgMKT.ImageUrl = "~/Image/green.png"
                Else
                    imgMKT.ImageUrl = "~/Image/red.png"
                End If
            ElseIf (gridItem.DataKeys(e.Row.RowIndex).Values("Marketing_approve") & "" = "") Then
                imgMKT.ImageUrl = "~/Image/red.png"
            Else
                imgMKT.ImageUrl = "~/Image/green.png"
            End If

            Dim dtap As DataTable = clsGet.Get_Load_Unload_Vessel(gridItem.DataKeys(e.Row.RowIndex).Values("Booking_no"))
            If (dtap.Rows.Count > 0) Then
                If (dtap.Rows(0).Item("Status") & "" = "C") Then
                    imgApprove.ImageUrl = "~/Image/blue.png"
                    imgApprove.ToolTip = "Waiting Approve by PTOLSEC"
                ElseIf (dtap.Rows(0).Item("Status") & "" = "A") Then
                    imgApprove.ImageUrl = "~/Image/green.png"
                    imgApprove.ToolTip = "Approve"
                ElseIf (dtap.Rows(0).Item("Status") & "" = "S") Then
                    imgApprove.ImageUrl = "~/Image/Yellow.png"
                    imgApprove.ToolTip = "Waiting Approve by PTOLSUP"
                ElseIf (dtap.Rows(0).Item("Status") & "" = "R") Then
                    imgApprove.ImageUrl = "~/Image/red.png"
                    imgApprove.ToolTip = "During Operation"
                Else
                    imgApprove.ImageUrl = "~/Image/red.png"
                    imgApprove.ToolTip = "During Operation"
                End If
            Else
                imgApprove.ImageUrl = "~/Image/red.png"
                imgApprove.ToolTip = "During Operation"
            End If

            If (gridItem.DataKeys(e.Row.RowIndex).Values("Remark_VPS") & "" <> "") Then
                imgVPSComment.Visible = True
            Else
                imgVPSComment.Visible = False
            End If
            If (gridItem.DataKeys(e.Row.RowIndex).Values("Remark_MRI") & "" <> "") Then
                imgMRIComment.Visible = True
            Else
                imgMRIComment.Visible = False
            End If

            Dim imgConfrim As Image = CType(e.Row.FindControl("imgConfrim"), Image)
            If (gridItem.DataKeys(e.Row.RowIndex).Values("Confirm_Time") & "" = "Y") Then
                imgConfrim.ImageUrl = "~/Image/4558.png"
            Else
                imgConfrim.ImageUrl = "~/Image/4557.gif"
            End If

            Dim Status As String = ""
            Dim Tooltip As String = ""
            clsGet.GetStatus_Working(gridItem.DataKeys(e.Row.RowIndex).Values("Booking_no"), gridItem.DataKeys(e.Row.RowIndex).Values("PORT"), Status, Tooltip)
            e.Row.Cells(2).Text = Status
            e.Row.Cells(2).ToolTip = Tooltip

            If (gridItem.DataKeys(e.Row.RowIndex).Values("Date_From") & "" <> "") Then
                If (gridItem.DataKeys(e.Row.RowIndex).Values("Date_From") & "" = gridItem.DataKeys(e.Row.RowIndex).Values("Date_To") & "") Then
                    e.Row.Cells(4).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Date_To")
                Else
                    e.Row.Cells(4).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Date_From").ToString.Substring(0, 2) & "-" & gridItem.DataKeys(e.Row.RowIndex).Values("Date_To")
                End If

                e.Row.Cells(5).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Booking_Date") & " : " & gridItem.DataKeys(e.Row.RowIndex).Values("Booking_Time")
                e.Row.Cells(6).Text = e.Row.Cells(6).Text & " hours"
                If (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_Destination") & "" = "O") Then
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_TypeBuy") & "" = "F") Then
                        e.Row.Cells(18).Text = "FOB" 'รูปแบบการซื้อขาย
                    ElseIf (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_TypeBuy") & "" = "C") Then
                        e.Row.Cells(18).Text = "CFR"
                    ElseIf (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_TypeBuy") & "" = "I") Then
                        e.Row.Cells(18).Text = "CIF"
                    Else
                        e.Row.Cells(18).Text = "อื่นๆ" 'รูปแบบการซื้อขาย
                    End If
                Else
                    e.Row.Cells(18).Text = "" 'รูปแบบการซื้อขาย
                    e.Row.Cells(17).Text = ""
                End If
                If (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage_Money") & "" = "B") Then
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & "" = "") Then
                        e.Row.Cells(17).Text = "- BAHT"
                    Else
                        e.Row.Cells(17).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & " BAHT "
                    End If
                ElseIf (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage_Money") & "" = "U") Then
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & "" = "") Then
                        e.Row.Cells(17).Text = "- USD"
                    Else
                        e.Row.Cells(17).Text = gridItem.DataKeys(e.Row.RowIndex).Values("Demurrage") & " USD "
                    End If
                End If
            End If

            Dim Product_Name As String = ""
            Dim Product_Amount As String = ""
            Dim Owner_name As String = ""
            Dim dtLog As DataTable
            dtLog = clsGet.Get_Booking_Product(gridItem.DataKeys(e.Row.RowIndex).Values("Booking_no"))
            For Each dr As DataRow In dtLog.Rows
                If (dr.Item("Product_name") & "" <> "") Then
                    If (Product_Name <> "") Then
                        Product_Name &= "<br />" & dr.Item("Product_name") & ""
                        Product_Amount &= "<br />" & dr.Item("Product_Amount") & ""
                        Owner_name &= "<br />" & dr.Item("Owner_Product_Name") & ""
                    Else
                        Product_Name = dr.Item("Product_name") & ""
                        Product_Amount = dr.Item("Product_Amount") & ""
                        Owner_name = dr.Item("Owner_Product_Name") & ""
                    End If
                End If
            Next
            If (gridItem.DataKeys(e.Row.RowIndex).Values("BunkerFO_Point") & "" <> "") And (gridItem.DataKeys(e.Row.RowIndex).Values("BunkerFO_Point") & "" <> "0") Then
                'BunkerFO 1 คัน,BunkerDO 1 คัน
                If Product_Name = "" Then
                    Product_Name = "BunkerFO"
                    Product_Amount = gridItem.DataKeys(e.Row.RowIndex).Values("BunkerFO_Point") & " คัน"
                Else
                    Product_Name &= "<br />" & "BunkerFO"
                    Product_Amount &= "<br />" & gridItem.DataKeys(e.Row.RowIndex).Values("BunkerFO_Point") & " คัน"
                End If
            End If
            If (gridItem.DataKeys(e.Row.RowIndex).Values("BunkerDO_Point") & "" <> "") And (gridItem.DataKeys(e.Row.RowIndex).Values("BunkerDO_Point") & "" <> "0") Then
                If Product_Name = "" Then
                    Product_Name = "BunkerDO"
                    Product_Amount = gridItem.DataKeys(e.Row.RowIndex).Values("BunkerDO_Point") & " คัน"
                Else
                    Product_Name &= "<br />" & "BunkerDO"
                    Product_Amount &= "<br />" & gridItem.DataKeys(e.Row.RowIndex).Values("BunkerDO_Point") & " คัน"
                End If
            End If
            Dim File_Upload As String = ""
            If (gridItem.DataKeys(e.Row.RowIndex).Values("File_Upload") & "" <> "") Then
                For i As Integer = 0 To gridItem.DataKeys(e.Row.RowIndex).Values("File_Upload").ToString.Split(",").Length - 1
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("File_Upload").ToString.Split(",")(i) & "" <> "") Then
                        If File_Upload = "" Then
                            File_Upload = gridItem.DataKeys(e.Row.RowIndex).Values("File_Upload").ToString.Split(",")(i)
                        Else
                            File_Upload &= "<br />" & gridItem.DataKeys(e.Row.RowIndex).Values("File_Upload").ToString.Split(",")(i)
                        End If
                    End If
                Next
            End If
            e.Row.Cells(7).Text = File_Upload
            e.Row.Cells(8).Text = Product_Name
            e.Row.Cells(9).Text = Product_Amount
            Dim Unit() As String = (gridItem.DataKeys(e.Row.RowIndex).Values("Product_Unit") & "").ToString.Split(",")
            Dim Text As String = ""
            For i As Integer = 0 To Unit.Length - 1
                If (Unit(i) & "" <> "") Then
                    If (Text = "") Then
                        Text = Unit(i)
                    Else
                        Text &= "<br />" & Unit(i)
                    End If
                End If
            Next
            e.Row.Cells(10).Text = Text
            Text = ""
            Unit = (gridItem.DataKeys(e.Row.RowIndex).Values("BUYER") & "").ToString.Split(",")
            For i As Integer = 0 To Unit.Length - 1
                If (Unit(i) & "" <> "") Then
                    If (Text = "") Then
                        Text = Unit(i)
                    Else
                        Text &= "<br />" & Unit(i)
                    End If
                End If
            Next
            e.Row.Cells(11).Text = Text
            Text = ""
            Unit = (gridItem.DataKeys(e.Row.RowIndex).Values("SELLER") & "").ToString.Split(",")
            For i As Integer = 0 To Unit.Length - 1
                If (Unit(i) & "" <> "") Then
                    If (Text = "") Then
                        Text = Unit(i)
                    Else
                        Text &= "<br />" & Unit(i)
                    End If
                End If
            Next
            e.Row.Cells(12).Text = Text
            If (clsFc.GetStatusCancel(gridItem.DataKeys(e.Row.RowIndex).Values("Status"))) Then
                e.Row.BackColor = Drawing.Color.Red
            Else
                Dim Product_Event As String = clsGet.Get_ProductEvent(gridItem.DataKeys(e.Row.RowIndex).Values("Booking_no"))
                If (Product_Event = "L") Then
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_Destination") & "" = "O") Then
                        e.Row.BackColor = Drawing.Color.FromName("#6698FF")
                    Else
                        e.Row.BackColor = Drawing.Color.FromName("#A0CFEC")
                    End If
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("PORT") & "" = "B") Then
                        e.Row.Cells(12).Text = Owner_name
                    End If
                ElseIf (Product_Event = "D") Then
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("Vehicle_Destination") & "" = "O") Then
                        e.Row.BackColor = Drawing.Color.FromName("#347C17")
                    Else
                        e.Row.BackColor = Drawing.Color.FromName("#52D017")
                    End If
                    If (gridItem.DataKeys(e.Row.RowIndex).Values("PORT") & "" = "B") Then
                        e.Row.Cells(11).Text = Owner_name
                    End If
                Else
                    e.Row.BackColor = Drawing.Color.White
                End If
            End If
        ElseIf (e.Row.RowType = DataControlRowType.Pager) Then
            Dim Page As GridViewRow = gridItem.BottomPagerRow
            Dim ddlPage As DropDownList = CType(e.Row.FindControl("ddlPage"), DropDownList)
            Dim lblPageCount As Label = CType(e.Row.FindControl("lbPageCount"), Label)
            If Not (ddlPage Is Nothing) Then
                For i As Integer = 0 To gridItem.PageCount - 1
                    Dim intPageNumber As Integer = i + 1
                    Dim IsItem As New ListItem(intPageNumber.ToString())
                    If (i = gridItem.PageIndex) Then
                        IsItem.Selected = True
                    End If
                    ddlPage.Items.Add(IsItem)
                Next
            End If
            If Not (lblPageCount Is Nothing) Then
                lblPageCount.Text = gridItem.PageCount.ToString()
            End If
        End If
    End Sub

    Private Sub gridItem_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gridItem.RowEditing

    End Sub
    Private Function PlusHourMinute(ByVal Original As String, ByVal Plus As String) As String
        Dim Hour As Integer = Original.Split(":")(0)
        Dim Minute As Integer = Original.Split(":")(1)
        Hour += CInt(Plus.Split(":")(0))
        Minute += CInt(Plus.Split(":")(1))
        If (Minute > 60) Then
            Hour += Minute / 60
            Minute = Minute Mod 60
        End If
        Return Hour.ToString("00") & ":" & Minute.ToString("00")
    End Function
    Private Sub StandartTimeValue(ByVal i As Integer)
        Dim Facility As String = gridProduct.DataKeys(i).Values("Facility_Code")
        Dim Shore As String = gridProduct.DataKeys(i).Values("Shore_Code")
        Dim Line As String = gridProduct.DataKeys(i).Values("Line_Code")
        Dim LD As String = gridProduct.DataKeys(i).Values("Product_Event")
        Dim Group_no As String = gridProduct.DataKeys(i).Values("Group_no")
        Dim lbTargetQuatity As Label = CType(gridProduct.Rows(i).FindControl("lbTargetQuatity"), Label)
        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
        Dim dt As DataTable = clsGet.Get_BookingWharf(ViewState("EditBooking"))
        Dim BookingWharf As String = dt.Rows(0).Item("BookingWharf") & ""
        dt = clsGet.Get_StandardTimeLiquid(Shore, Group_no, Line, LD, BookingWharf, Facility)
        Dim lbQuatity As TextBox
        If (LD = "L") Then
            If (dt.Rows(0).Item("Unit") & "" = "M3") Then
                lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLM3_Load"), TextBox)
            Else
                lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLMT_Load"), TextBox)
            End If
        Else
            If (dt.Rows(0).Item("Unit") & "" = "M3") Then
                lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLFig"), TextBox)
            Else
                lbQuatity = CType(gridProduct.Rows(i).FindControl("txtBLFigMT"), TextBox)
            End If
        End If
        Dim Value As String = ""
        If (lbQuatity.Text = "") Then
            Value = lbTargetQuatity.Text
        Else
            Value = lbQuatity.Text
        End If
        Dim Before As String
        Dim After As String

        Dim StandardTime As Integer = 1
        Try
            StandardTime = CDbl(Value) / (CDbl(dt.Rows(0).Item("Rate")) / 60)
        Catch ex As Exception

        End Try
        If (dt.Rows.Count > 0) Then
            Dim LPG As Boolean = False
            Dim BUTANE As Boolean = False
            Dim LPG_BUTANE As Boolean = Facility
            For x As Integer = 0 To gridProduct.Rows.Count - 1
                If (gridProduct.DataKeys(x).Values("Group_no") = "00031") Or (gridProduct.DataKeys(x).Values("Group_no") = "00064") Then
                    LPG = True
                End If
                If (gridProduct.DataKeys(x).Values("Group_no") = "00034") Then
                    BUTANE = True
                End If
            Next
            If (LPG) And (BUTANE) Then
                dt = clsGet.Get_StandardTimeLiquid(Shore, "00033", Line, LD, BookingWharf, Facility)
            End If
            Before = CInt(dt.Rows(0).Item("Before").ToString.Split(":")(0)).ToString("00") & ":" & CInt(dt.Rows(0).Item("Before").ToString.Split(":")(1)).ToString("00")
            After = CInt(dt.Rows(0).Item("After").ToString.Split(":")(0)).ToString("00") & ":" & CInt(dt.Rows(0).Item("After").ToString.Split(":")(1)).ToString("00")
            Dim C_Product As Integer = 0
            Dim C_Parcel As Integer = 0
            Dim _Product As String = ""
            Dim _Group As String = dt.Rows(0).Item("Group_Code")
            If (dt.Rows(0).Item("Plus_Product_Before") & "" <> "00:00") Or (dt.Rows(0).Item("Plus_Product_After") & "" <> "00:00") Then
                For x As Integer = 0 To gridProduct.Rows.Count - 1
                    If (_Group = CInt(gridProduct.DataKeys(x).Values("Group_no") & "")) Then
                        C_Parcel += 1
                        'Dim Find As Integer = InStr(_Product, gridProduct.DataKeys(x).Values("Product_no"), CompareMethod.Text)
                        'If (Find = 0) Then
                        '    C_Product += 1
                        'End If
                        If (_Product = gridProduct.DataKeys(x).Values("Product_no")) Then
                            C_Product += 1
                        End If
                    End If
                    ' _Product &= gridProduct.DataKeys(x).Values("Product_no") & ","
                    _Product = gridProduct.DataKeys(x).Values("Product_no")
                Next
            ElseIf (dt.Rows(0).Item("Plus_Parcel_Before") & "" <> "00:00") Or (dt.Rows(0).Item("Plus_Parcel_After") & "" <> "00:00") Then
                'Parcel
                For x As Integer = 0 To gridProduct.Rows.Count - 1
                    If (_Group = CInt(gridProduct.DataKeys(x).Values("Group_no") & "")) Then
                        C_Parcel += 1
                    End If
                Next
            End If
            If (C_Product > 1) Then
                Dim PlusTime As String = "00:00"
                For n = 1 To C_Product - 1
                    PlusTime = PlusHourMinute(PlusTime, dt.Rows(0).Item("Plus_Product_Before"))
                Next
                Before = PlusHourMinute(Before, PlusTime)
            ElseIf (C_Parcel > 1) Then
                Dim PlusTime As String = "00:00"
                For n = 1 To C_Parcel - 1
                    PlusTime = PlusHourMinute(PlusTime, dt.Rows(0).Item("Plus_Parcel_Before"))
                Next
                Before = PlusHourMinute(Before, PlusTime)
            End If
        Else
            Before = "00:00"
            After = "00:00"
        End If
        '*********************************
        'ทำการคูณ Before   ****************
        '********************************
        Dim ds As DataSet = Session("Config")
        If ((ds.Tables(0).Rows(0).Item("Before") & "" <> "") And (ds.Tables(0).Rows(0).Item("Before") & "" <> "0")) Then
            Dim MinuteBeforePlus As Integer = CInt(ds.Tables(0).Rows(0).Item("Before"))
            MinuteBeforePlus = MinuteBeforePlus * gridProduct.Rows.Count
            Before = PlusHourMinute(Before, MinuteBeforePlus \ 60 & ":" & MinuteBeforePlus Mod 60)
        End If
        If ((ds.Tables(0).Rows(0).Item("After") & "" <> "") And (ds.Tables(0).Rows(0).Item("After") & "" <> "0")) Then
            Dim MinuteAfterPlus As Integer = CInt(ds.Tables(0).Rows(0).Item("After"))
            MinuteAfterPlus = MinuteAfterPlus * gridProduct.Rows.Count
            After = PlusHourMinute(Before, MinuteAfterPlus \ 60 & ":" & MinuteAfterPlus Mod 60)
        End If

        If (txtPlus_Tank.Text > 0) Then
            Try
                Dim Plus As Double = CDbl(dt.Rows(0).Item("Plus_Tank") & "")
                Plus = Plus * CDbl(txtPlus_Tank.Text)
                If (CInt(Plus.ToString.Split(".").Length > 1)) Then
                    If (CInt(Plus.ToString.Split(".")(1).ToString()) > 0) Then
                        Dim MI As Integer
                        If (Plus.ToString.Split(".")(1).Length = 1) Then
                            MI = CInt(Plus.ToString.Split(".")(1) * 6)
                        Else
                            MI = CInt(Plus.ToString.Split(".")(1) * 60) / 100
                        End If
                        MI = MI + CInt(Before.Split(":")(1))
                        If (MI > 59) Then
                            Before = (CInt(Before.Split(":")(0)) + (CInt(Plus.ToString.Split(".")(0)) + 1)).ToString("00") & ":" & (MI Mod 60).ToString("00")
                        Else
                            Before = (CInt(Before.Split(":")(0)) + CInt(Plus.ToString.Split(".")(0))).ToString("00") & ":" & MI.ToString("00")
                        End If
                    Else
                        Before = (CInt(Before.Split(":")(0)) + CInt(Plus.ToString.Split(".")(0))).ToString("00") & ":" & Before.Split(":")(1)
                    End If
                Else
                    Before = (CInt(Before.Split(":")(0)) + CInt(Plus.ToString.Split(".")(0))).ToString("00") & ":" & Before.Split(":")(1)
                End If

            Catch ex As Exception

            End Try


        End If


        '*************************
        Dim Hour As Integer
        Dim Minute As Integer
        If (i = 0) Then
            Hour = CInt(lbBerthed.Text.Split(":")(0))
            Minute = CInt(lbBerthed.Text.Split(":")(1))
        Else
            Hour = CType(gridProduct.Rows(i - 1).FindControl("lbStopStandard"), Label).Text.Split(":")(0)
            Minute = CType(gridProduct.Rows(i - 1).FindControl("lbStopStandard"), Label).Text.Split(":")(1)
        End If

        Dim plussss As Boolean = False
        If (Hour = 23) Then
            plussss = True
        End If
        Dim _StartStandardTime As String = (Hour + 1).ToString("00") & ":" & Minute.ToString("00")
        Hour += CInt(Before.Split(":")(0))
        Minute += CInt(Before.Split(":")(1))
        Dim PlusHour As Integer = 0
        PlusHour = Minute \ 60
        Minute = Minute Mod 60
        Hour += PlusHour
        Dim PlusDay As Integer = 0
        If (Hour > 23) Then
            PlusDay = Hour / 24
            Hour = Hour Mod 24
        End If
        If (i = 0) Then
            If (PlusDay > 0) Then
                plussss = True
            Else
                plussss = False
            End If
        End If
        Dim lbStartStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandardDate"), Label)
        Dim lbStartStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandard"), Label)
        Dim lbStopStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandardDate"), Label)
        Dim lbStopStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandard"), Label)

        If (PlusDay > 0) Then
            'If (CInt(_StartStandardTime.ToString.Split(":")(0)) > 0) Then
            If (i = 0) Then
                lbStartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBerthedDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
            Else
                Dim lbstopstandardOld As Label = CType(gridProduct.Rows(i - 1).FindControl("lbStopStandardDate"), Label)
                lbStartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbstopstandardOld.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
            End If

        Else
            If (i = 0) Then
                lbStartStandardDate.Text = lbBerthedDate.Text
            Else
                Dim lbstopstandardOld As Label = CType(gridProduct.Rows(i - 1).FindControl("lbStopStandardDate"), Label)
                lbStartStandardDate.Text = lbstopstandardOld.Text
            End If

        End If
        If (i = 0) Then
            lbStartStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")
        Else
            lbStartStandard.Text = _StartStandardTime
        End If

        Hour += StandardTime \ 60
        Minute += StandardTime Mod 60
        PlusHour = Minute \ 60
        Minute = Minute Mod 60
        Hour += PlusHour
        PlusDay = 0
        If (Hour > 23) Then
            PlusDay = Hour \ 24
            Hour = Hour Mod 24
        End If

        If (PlusDay > 0) Then
            lbStopStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbStartStandardDate.Text.Substring(0, 2) & GetNameMonth(lbStartStandardDate.Text.Substring(3, 2)) & "20" & lbStartStandardDate.Text.Substring(6, 2))).AddDays(PlusDay).ToString("dd/MM/yy")
        Else
            lbStopStandardDate.Text = lbStartStandardDate.Text
        End If
        lbStopStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")

        ViewState("StandardTimeProductLast") = lbStopStandard.Text
        ViewState("StandardTimeProductLastDate") = lbStopStandardDate.Text

        lbBunkerStandard.Text = lbStopStandard.Text
        lbBunkerStandardDate.Text = lbStopStandardDate.Text
        ViewState("AfterStandardTime") = After
        Hour += CInt(After.Split(":")(0))
        Minute += CInt(After.Split(":")(1))
        PlusHour = 0
        PlusHour = Minute \ 60
        Minute = Minute Mod 60
        Hour += PlusHour
        PlusDay = 0
        If (Hour > 23) Then
            PlusDay = Hour / 24
            Hour = Hour Mod 24
        End If

        If (PlusDay > 0) Then
            lbDepartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBunkerStandardDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
        Else
            lbDepartStandardDate.Text = lbBunkerStandardDate.Text
        End If
        lbDepartStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")
    End Sub

    Protected Sub txtPlus_Tank_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim txtBLFig = DirectCast(sender, TextBox)
            Dim chk As Boolean = False
            For i As Integer = 0 To gridProduct.Rows.Count - 1
                Dim lbTargetQuatity As Label = CType(gridProduct.Rows(i).FindControl("lbTargetQuatity"), Label)
                If (txtBLFig.ClientID.Substring(0, 43) = lbTargetQuatity.ClientID.Substring(0, 43)) Or (chk) Then
                    chk = True
                    StandartTimeValue(i)
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub
    Protected Sub txtBLFig_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim txtBLFig = DirectCast(sender, TextBox)
            Dim chk As Boolean = False
            For i As Integer = 0 To gridProduct.Rows.Count - 1
                Dim lbTargetQuatity As Label = CType(gridProduct.Rows(i).FindControl("lbTargetQuatity"), Label)
                If (txtBLFig.ClientID.Substring(0, 43) = lbTargetQuatity.ClientID.Substring(0, 43)) Or (chk) Then
                    chk = True
                    StandartTimeValue(i)
                End If
            Next
        Catch ex As Exception

        End Try

    End Sub

    Private Sub gridProduct_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridProduct.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If (ViewState("Load") = "Not") Then
                Exit Sub 'ไม่พบข้อมูล STD
            End If
            ' Dim ddlPre1 As DropDownList = CType(e.Row.FindControl("ddlPre1"), DropDownList)
            ' ทำการดึง Before มา
            Dim Facility As String = gridProduct.DataKeys(e.Row.RowIndex).Values("Facility_Code")
            Dim Shore As String = gridProduct.DataKeys(e.Row.RowIndex).Values("Shore_Code")
            Dim Line As String = gridProduct.DataKeys(e.Row.RowIndex).Values("Line_Code")
            Dim LD As String = gridProduct.DataKeys(e.Row.RowIndex).Values("Product_Event")
            Dim Group_no As String = gridProduct.DataKeys(e.Row.RowIndex).Values("Group_no")
            Dim dt As DataTable = clsGet.Get_Shore(Shore, "L")
            lbShore.Text = dt.Rows(0).Item("Shore_Name") & ""
            Dim lbTargetQuatity As Label = CType(e.Row.FindControl("lbTargetQuatity"), Label)
            lbTargetQuatity.Text = gridProduct.DataKeys(e.Row.RowIndex).Values("Product_Amount") & ""
            dt = clsGet.Get_BookingWharf(ViewState("EditBooking"))
            If (dt.Rows.Count > 0) Then
                lbWharf.Text = dt.Rows(0).Item("Wharf") & ""
                Dim BookingWharf As String = dt.Rows(0).Item("BookingWharf")
                Dim rowBL_Disch As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowBL_Disch"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowSL_Disch As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowSL_Disch"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowSU_Disch As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowSU_Disch"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowShoreRecieve_Disch As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowShoreRecieve_Disch"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowShore_Disch As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowShore_Disch"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowShip_Disch As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowShip_Disch"), System.Web.UI.HtmlControls.HtmlTableRow)

                Dim rowBL_Load As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowBL_Load"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowSL_Load As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowSL_Load"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowShore_Load As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowShore_Load"), System.Web.UI.HtmlControls.HtmlTableRow)
                Dim rowShip_Load As System.Web.UI.HtmlControls.HtmlTableRow = CType(e.Row.FindControl("rowShip_Load"), System.Web.UI.HtmlControls.HtmlTableRow)

                dt = clsGet.Get_Load_Unload_Product_PTOL(ViewState("EditBooking"), gridProduct.DataKeys(e.Row.RowIndex).Values("Product_no"), ViewState("EditBooking") & gridProduct.DataKeys(e.Row.RowIndex).Values("Product_no") & gridProduct.DataKeys(e.Row.RowIndex).Values("Product_Index"))
                If (dt.Rows.Count > 0) Then
                    Dim txtLineBeforeFrom As TextBox = CType(e.Row.FindControl("txtLineBeforeFrom"), TextBox)
                    Dim txtLineBeforeTo As TextBox = CType(e.Row.FindControl("txtLineBeforeTo"), TextBox)
                    Dim txtConnectDate As TextBox = CType(e.Row.FindControl("txtConnectDate"), TextBox)
                    Dim txtConnectMLAFrom As TextBox = CType(e.Row.FindControl("txtConnectMLAFrom"), TextBox)
                    Dim txtConnectMLATo As TextBox = CType(e.Row.FindControl("txtConnectMLATo"), TextBox)
                    Dim lbStartStandardDate_P As Label = CType(e.Row.FindControl("lbStartStandardDate"), Label)
                    Dim lbStartStandard_P As Label = CType(e.Row.FindControl("lbStartStandard"), Label)
                    Dim txtStartActualDate As TextBox = CType(e.Row.FindControl("txtStartActualDate"), TextBox)
                    Dim txtStartActualTime As TextBox = CType(e.Row.FindControl("txtStartActualTime"), TextBox)
                    Dim lbStopStandardDate_P As Label = CType(e.Row.FindControl("lbStopStandardDate"), Label)
                    Dim lbStopStandard_P As Label = CType(e.Row.FindControl("lbStopStandard"), Label)
                    Dim txtStopActualDate As TextBox = CType(e.Row.FindControl("txtStopActualDate"), TextBox)
                    Dim txtStopActualTime As TextBox = CType(e.Row.FindControl("txtStopActualTime"), TextBox)
                    Dim txtLineafterFrom As TextBox = CType(e.Row.FindControl("txtLineafterFrom"), TextBox)
                    Dim txtLineafterTo As TextBox = CType(e.Row.FindControl("txtLineafterTo"), TextBox)
                    Dim txtDisDate As TextBox = CType(e.Row.FindControl("txtDisDate"), TextBox)
                    Dim txtDisMLAFrom As TextBox = CType(e.Row.FindControl("txtDisMLAFrom"), TextBox)
                    Dim txtDisMLATo As TextBox = CType(e.Row.FindControl("txtDisMLATo"), TextBox)
                    Dim txtPlus_Tank As TextBox = CType(e.Row.FindControl("txtPlus_Tank"), TextBox)

                    txtPlus_Tank.Text = dt.Rows(0).Item("Plus_Tank") & ""
                    txtLineBeforeFrom.Text = dt.Rows(0).Item("LU_Fill_From") & ""
                    txtLineBeforeTo.Text = dt.Rows(0).Item("LU_Fill_To") & ""
                    txtConnectDate.Text = dt.Rows(0).Item("LU_Connect_Date") & ""
                    txtConnectMLAFrom.Text = dt.Rows(0).Item("LU_Connect_From") & ""
                    txtConnectMLATo.Text = dt.Rows(0).Item("LU_Connect_To") & ""
                    lbStartStandardDate_P.Text = dt.Rows(0).Item("LU_StartStandard_Date") & ""
                    lbStartStandard_P.Text = dt.Rows(0).Item("LU_StartStandard_Time") & ""
                    txtStartActualDate.Text = dt.Rows(0).Item("LU_StartActual_Date") & ""
                    If (txtStartActualDate.Text.Trim() <> "") Then
                        ViewState("Start") = True
                    End If
                    txtStartActualTime.Text = dt.Rows(0).Item("LU_StartActual_Time") & ""
                    lbStopStandardDate_P.Text = dt.Rows(0).Item("LU_StopStandard_Date") & ""
                    lbStopStandard_P.Text = dt.Rows(0).Item("LU_StopStandard_Time") & ""
                    txtStopActualDate.Text = dt.Rows(0).Item("LU_StopActual_Date") & ""
                    txtStopActualTime.Text = dt.Rows(0).Item("LU_StopActual_Time") & ""
                    txtLineafterFrom.Text = dt.Rows(0).Item("LU_Fillafter_From") & ""
                    txtLineafterTo.Text = dt.Rows(0).Item("LU_Fillafter_To") & ""
                    txtDisDate.Text = dt.Rows(0).Item("LU_Disconnect_Date") & ""
                    txtDisMLAFrom.Text = dt.Rows(0).Item("LU_Disconnect_From") & ""
                    txtDisMLATo.Text = dt.Rows(0).Item("LU_Disconnect_To") & ""


                    If LD = "L" Then
                        Dim txtBLM3_Load As TextBox = CType(e.Row.FindControl("txtBLM3_Load"), TextBox)
                        Dim txtBLMT_Load As TextBox = CType(e.Row.FindControl("txtBLMT_Load"), TextBox)
                        Dim txtSLM3_Load As TextBox = CType(e.Row.FindControl("txtSLM3_Load"), TextBox)
                        Dim txtSLMT_LOad As TextBox = CType(e.Row.FindControl("txtSLMT_LOad"), TextBox)
                        Dim txtAPIShore_Load As TextBox = CType(e.Row.FindControl("txtAPIShore_Load"), TextBox)
                        Dim txtViscosityShore_Load As TextBox = CType(e.Row.FindControl("txtViscosityShore_Load"), TextBox)
                        Dim txtAPIShip_Load As TextBox = CType(e.Row.FindControl("txtAPIShip_Load"), TextBox)
                        Dim txtViscositShip_Load As TextBox = CType(e.Row.FindControl("txtViscositShip_Load"), TextBox)

                        txtBLM3_Load.Text = dt.Rows(0).Item("LU_BL") & ""
                        txtBLMT_Load.Text = dt.Rows(0).Item("LU_BLMT") & ""
                        txtSLM3_Load.Text = dt.Rows(0).Item("LU_SL") & ""
                        txtSLMT_LOad.Text = dt.Rows(0).Item("LU_SLMT") & ""
                        txtAPIShore_Load.Text = dt.Rows(0).Item("API_Shore") & ""
                        txtViscosityShore_Load.Text = dt.Rows(0).Item("Vis_Shore") & ""
                        txtAPIShip_Load.Text = dt.Rows(0).Item("API_Ship") & ""
                        txtViscositShip_Load.Text = dt.Rows(0).Item("Vis_Ship") & ""


                    Else
                        Dim txtBLFig As TextBox = CType(e.Row.FindControl("txtBLFig"), TextBox)
                        Dim txtBLFigMT As TextBox = CType(e.Row.FindControl("txtBLFigMT"), TextBox)
                        Dim txtSLFig As TextBox = CType(e.Row.FindControl("txtSLFig"), TextBox)
                        Dim txtSLFigMT As TextBox = CType(e.Row.FindControl("txtSLFigMT"), TextBox)
                        Dim txtAPIShore As TextBox = CType(e.Row.FindControl("txtAPIShore"), TextBox)
                        Dim txtAPIShip As TextBox = CType(e.Row.FindControl("txtAPIShip"), TextBox)
                        Dim txtVisShore As TextBox = CType(e.Row.FindControl("txtVisShore"), TextBox)
                        Dim txtVisShip As TextBox = CType(e.Row.FindControl("txtVisShip"), TextBox)

                        Dim txtSUFig As TextBox = CType(e.Row.FindControl("txtSUFig"), TextBox)
                        Dim txtSUFigMT As TextBox = CType(e.Row.FindControl("txtSUFigMT"), TextBox)
                        Dim txtShoreReceive As TextBox = CType(e.Row.FindControl("txtShoreReceive"), TextBox)
                        Dim txtShoreReceiveMT As TextBox = CType(e.Row.FindControl("txtShoreReceiveMT"), TextBox)

                        ViewState("Start") = False
                        txtBLFig.Text = dt.Rows(0).Item("LU_BL") & ""
                        txtBLFigMT.Text = dt.Rows(0).Item("LU_BLMT") & ""
                        txtSLFig.Text = dt.Rows(0).Item("LU_SL") & ""
                        txtSLFigMT.Text = dt.Rows(0).Item("LU_SLMT") & ""
                        txtAPIShore.Text = dt.Rows(0).Item("API_Shore") & ""
                        txtAPIShip.Text = dt.Rows(0).Item("API_Ship") & ""
                        txtVisShore.Text = dt.Rows(0).Item("Vis_Shore") & ""
                        txtVisShip.Text = dt.Rows(0).Item("Vis_Ship") & ""

                        txtSUFig.Text = dt.Rows(0).Item("LU_SU") & ""
                        txtSUFigMT.Text = dt.Rows(0).Item("LU_SUMT") & ""
                        txtShoreReceive.Text = dt.Rows(0).Item("LU_ShoreRecieve") & ""
                        txtShoreReceiveMT.Text = dt.Rows(0).Item("LU_ShoreRecieveMT") & ""
                    End If

                End If

                dt = clsGet.Get_StandardTimeLiquid(Shore, Group_no, Line, LD, BookingWharf & "", Facility)
                If (dt.Rows.Count > 0) Then
                    Dim lbQuatity As TextBox
                    If (LD = "L") Then
                        lbDirection.Text = "LOADING"
                        rowBL_Load.Visible = True
                        rowSL_Load.Visible = True
                        rowShip_Load.Visible = True
                        rowShore_Load.Visible = True


                        rowBL_Disch.Visible = False
                        rowSL_Disch.Visible = False
                        rowSU_Disch.Visible = False
                        rowShoreRecieve_Disch.Visible = False
                        rowShore_Disch.Visible = False
                        rowShip_Disch.Visible = False

                        If (dt.Rows.Count > 0) Then
                            If (dt.Rows(0).Item("Unit") & "" = "M3") Then
                                lbQuatity = CType(e.Row.FindControl("txtBLM3_Load"), TextBox)
                            Else
                                lbQuatity = CType(e.Row.FindControl("txtBLMT_Load"), TextBox)
                            End If
                        End If

                    Else
                        lbDirection.Text = "UNLOADING"

                        rowBL_Disch.Visible = True
                        rowSL_Disch.Visible = True
                        rowSU_Disch.Visible = True
                        rowShoreRecieve_Disch.Visible = True
                        rowShore_Disch.Visible = True
                        rowShip_Disch.Visible = True

                        rowBL_Load.Visible = False
                        rowSL_Load.Visible = False
                        rowShip_Load.Visible = False
                        rowShore_Load.Visible = False
                        If (dt.Rows.Count > 0) Then
                            If (dt.Rows(0).Item("Unit") & "" = "M3") Then
                                lbQuatity = CType(e.Row.FindControl("txtBLFig"), TextBox)
                            Else
                                lbQuatity = CType(e.Row.FindControl("txtBLFigMT"), TextBox)
                            End If
                        End If

                    End If
                    Dim Value As String = ""
                    If (lbQuatity.Text = "") Then
                        Value = lbTargetQuatity.Text
                    Else
                        Value = lbQuatity.Text
                    End If
                    Dim Before As String
                    Dim After As String

                    Dim StandardTime As Integer = 1
                    Try
                        StandardTime = CDbl(Value) / (CDbl(dt.Rows(0).Item("Rate")) / 60)
                    Catch ex As Exception

                    End Try
                    If (dt.Rows.Count > 0) Then
                        Before = CInt(dt.Rows(0).Item("Before").ToString.Split(":")(0)).ToString("00") & ":" & CInt(dt.Rows(0).Item("Before").ToString.Split(":")(1)).ToString("00")
                        After = CInt(dt.Rows(0).Item("After").ToString.Split(":")(0)).ToString("00") & ":" & CInt(dt.Rows(0).Item("After").ToString.Split(":")(1)).ToString("00")
                    Else
                        Before = "00:00"
                        After = "00:00"
                    End If

                    '*******************************************************
                    'ทำการคูณ Before , After ข้อมูลมาจาก config   **************************************
                    '******************************************************
                    Dim ds As DataSet = Session("Config")
                    If ((ds.Tables(0).Rows(0).Item("Before") & "" <> "") And (ds.Tables(0).Rows(0).Item("Before") & "" <> "0")) Then
                        Dim MinuteBeforePlus As Integer = CInt(ds.Tables(0).Rows(0).Item("Before"))
                        MinuteBeforePlus = MinuteBeforePlus * gridProduct.Rows.Count
                        Before = PlusHourMinute(Before, MinuteBeforePlus \ 60 & ":" & MinuteBeforePlus Mod 60)
                    End If
                    If ((ds.Tables(0).Rows(0).Item("After") & "" <> "") And (ds.Tables(0).Rows(0).Item("After") & "" <> "0")) Then
                        Dim MinuteAfterPlus As Integer = CInt(ds.Tables(0).Rows(0).Item("After"))
                        MinuteAfterPlus = MinuteAfterPlus * gridProduct.Rows.Count
                        After = PlusHourMinute(Before, MinuteAfterPlus \ 60 & ":" & MinuteAfterPlus Mod 60)
                    End If

                    '*******************************************************************

                    Dim Hour As Integer
                    Dim Minute As Integer
                    If (e.Row.RowIndex = 0) Then
                        Hour = CInt(lbBerthed.Text.Split(":")(0))
                        Minute = CInt(lbBerthed.Text.Split(":")(1))
                    Else
                        Hour = CType(gridProduct.Rows(e.Row.RowIndex - 1).FindControl("lbStopStandard"), Label).Text.Split(":")(0)
                        Minute = CType(gridProduct.Rows(e.Row.RowIndex - 1).FindControl("lbStopStandard"), Label).Text.Split(":")(1)
                    End If
                    Dim _StartStandardTime As String = (Hour + 1).ToString("00") & ":" & Minute.ToString("00")

                    Hour += CInt(Before.Split(":")(0))
                    Minute += CInt(Before.Split(":")(1))
                    Dim PlusHour As Integer = 0
                    PlusHour = Minute \ 60
                    Minute = Minute Mod 60
                    Hour += PlusHour
                    Dim PlusDay As Integer = 0
                    If (Hour > 23) Then
                        PlusDay = Hour / 24
                        Hour = Hour Mod 24
                    End If

                    Dim lbStartStandardDate As Label = CType(e.Row.FindControl("lbStartStandardDate"), Label)
                    Dim lbStartStandard As Label = CType(e.Row.FindControl("lbStartStandard"), Label)
                    Dim lbStopStandardDate As Label = CType(e.Row.FindControl("lbStopStandardDate"), Label)
                    Dim lbStopStandard As Label = CType(e.Row.FindControl("lbStopStandard"), Label)

                    'If (PlusDay > 0) Then
                    '    lbStartStandardDate.Text = CDate(lbBerthedDate.Text).AddDays(PlusDay).ToString("dd/MM/yy")
                    'Else
                    '    lbStartStandardDate.Text = lbBerthedDate.Text
                    'End If
                    'If (e.Row.RowIndex = 0) Then
                    '    lbStartStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")
                    'Else

                    'End If

                    If (CInt(_StartStandardTime.ToString.Split(":")(0)) > 0) Then
                        If (e.Row.RowIndex = 0) Then
                            lbStartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBerthedDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
                        Else
                            Dim lbstopstandardOld As Label = CType(gridProduct.Rows(e.Row.RowIndex - 1).FindControl("lbStopStandardDate"), Label)
                            lbStartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbstopstandardOld.Text)).AddDays(PlusDay).ToString("dd/MM/yy")

                        End If

                    Else
                        If (e.Row.RowIndex = 0) Then
                            lbStartStandardDate.Text = lbBerthedDate.Text
                        Else
                            Dim lbstopstandardOld As Label = CType(gridProduct.Rows(e.Row.RowIndex - 1).FindControl("lbStopStandardDate"), Label)
                            lbStartStandardDate.Text = lbstopstandardOld.Text
                        End If

                    End If
                    If (e.Row.RowIndex = 0) Then
                        lbStartStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")
                    Else
                        lbStartStandard.Text = _StartStandardTime
                    End If

                    Hour += StandardTime \ 60
                    Minute += StandardTime Mod 60
                    PlusHour = Minute \ 60
                    Minute = Minute Mod 60
                    Hour += PlusHour
                    PlusDay = 0
                    If (Hour > 23) Then
                        PlusDay = Hour / 24
                        Hour = Hour Mod 24
                    End If

                    If (PlusDay > 0) Then
                        lbStopStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBerthedDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
                    Else
                        lbStopStandardDate.Text = lbBerthedDate.Text
                    End If
                    lbStopStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")

                    ViewState("StandardTimeProductLast") = lbStopStandard.Text
                    ViewState("StandardTimeProductLastDate") = lbStopStandardDate.Text

                    lbBunkerStandard.Text = lbStopStandard.Text
                    lbBunkerStandardDate.Text = lbStopStandardDate.Text
                    ViewState("AfterStandardTime") = After
                    Hour += CInt(After.Split(":")(0))
                    Minute += CInt(After.Split(":")(1))
                    PlusHour = 0
                    PlusHour = Minute \ 60
                    Minute = Minute Mod 60
                    Hour += PlusHour
                    PlusDay = 0
                    If (Hour > 23) Then
                        PlusDay = Hour / 24
                        Hour = Hour Mod 24
                    End If

                    If (PlusDay > 0) Then
                        lbDepartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBunkerStandardDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
                    Else
                        lbDepartStandardDate.Text = lbBunkerStandardDate.Text
                    End If
                    lbDepartStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")
                Else
                    ' ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ไม่พบข้อมูล StandardTime กรุณาทำการตรวจสอบ Shore');", True)
                    ' LoadBOoking()
                    ViewState("Load") = "Not"
                    ' Timer1_Tick(sender, e)
                    Session("Delay") = Nothing
                    Session("TugBeforeLoading") = Nothing
                    Session("TugAfterLoading") = Nothing
                End If
            Else

                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ไม่พบข้อมูลการจองคิวท่าเรือ');", True)
                ViewState("Load") = "Not"
                Session("Delay") = Nothing
                Session("TugBeforeLoading") = Nothing
                Session("TugAfterLoading") = Nothing
            End If
        End If
    End Sub

    Private Sub txtBunker_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBunker.TextChanged
        Dim Time As Integer = CInt(txtBunker.Text) * 45
        'Dim Hour As Double = (CDbl(Time) / 60).ToString("####00.00").Split(".")(0)
        Dim Minute As Double = ((CDbl((CDbl(Time) / 60).ToString("####00.00").Split(".")(1)) / 100) * 60).ToString("#########.00")

        lbTruckTime.Text = (CDbl(Time) / 60).ToString("####00.00").Split(".")(0) & ":" & (Minute / 100).ToString("#####00.00").Split(".")(1)

        If (ViewState("StandardTimeProductLast") <> "") Then
            Dim Hour As Integer = lbTruckTime.Text.Split(":")(0)
            Minute = lbTruckTime.Text.Split(":")(1)
            Dim HourProduct As Integer = ViewState("StandardTimeProductLast").ToString().Split(":")(0)
            Dim MinuteProduct As Integer = ViewState("StandardTimeProductLast").ToString().Split(":")(1)
            Dim PlusHourBunker As Integer = 0
            Minute = Minute + MinuteProduct
            If (Minute > 59) Then
                PlusHourBunker = Minute / 60
            End If
            Minute = Minute Mod 60
            Hour = Hour + HourProduct + PlusHourBunker

            Dim PlusDay As Integer = 0
            If (Hour > 23) Then
                PlusDay = Hour / 24
                Hour = Hour Mod 24
            End If
            If (PlusDay > 0) Then
                lbBunkerStandardDate.Text = CDate(ClassFunctionGetData.CDateT(ViewState("StandardTimeProductLastDate"))).AddDays(PlusDay).ToString("dd/MM/yy")
            Else
                lbBunkerStandardDate.Text = ViewState("StandardTimeProductLastDate")
            End If

            lbBunkerStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")

            HourProduct = ViewState("AfterStandardTime").ToString().Split(":")(0)
            MinuteProduct = ViewState("AfterStandardTime").ToString().Split(":")(1)
            PlusHourBunker = 0
            Minute = Minute + MinuteProduct
            If (Minute > 59) Then
                PlusHourBunker = Minute / 60
            End If
            Minute = Minute Mod 60
            Hour = Hour + HourProduct + PlusHourBunker


            PlusDay = 0
            If (Hour > 23) Then
                PlusDay = Hour / 24
                Hour = Hour Mod 24
            End If
            If (PlusDay > 0) Then
                lbDepartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBunkerStandardDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
            Else
                lbDepartStandardDate.Text = lbBunkerStandardDate.Text
            End If
            lbDepartStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")
        Else
            Dim Hour As Integer = lbTruckTime.Text.Split(":")(0)
            Minute = lbTruckTime.Text.Split(":")(1)
            Dim HourProduct As Integer = lbBerthedStandard.Text.Split(":")(0)
            Dim MinuteProduct As Integer = lbBerthedStandard.Text.Split(":")(1)
            Dim PlusHourBunker As Integer = 0
            Minute = Minute + MinuteProduct
            If (Minute > 59) Then
                PlusHourBunker = Minute / 60
            End If
            Minute = Minute Mod 60
            Hour = Hour + HourProduct + PlusHourBunker

            Dim PlusDay As Integer = 0
            If (Hour > 23) Then
                PlusDay = Hour / 24
                Hour = Hour Mod 24
            End If
            If (PlusDay > 0) Then
                lbBunkerStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBerthedStandardDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
            Else
                lbBunkerStandardDate.Text = lbBerthedStandardDate.Text
            End If

            lbBunkerStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")

            HourProduct = 0
            MinuteProduct = 0
            PlusHourBunker = 0
            Minute = Minute + MinuteProduct
            If (Minute > 59) Then
                PlusHourBunker = Minute / 60
            End If
            Minute = Minute Mod 60
            Hour = Hour + HourProduct + PlusHourBunker


            PlusDay = 0
            If (Hour > 23) Then
                PlusDay = Hour / 24
                Hour = Hour Mod 24
            End If
            If (PlusDay > 0) Then
                lbDepartStandardDate.Text = CDate(ClassFunctionGetData.CDateT(lbBunkerStandardDate.Text)).AddDays(PlusDay).ToString("dd/MM/yy")
            Else
                lbDepartStandardDate.Text = lbBunkerStandardDate.Text
            End If
            lbDepartStandard.Text = Hour.ToString("00") & ":" & Minute.ToString("00")
        End If

    End Sub

    Private Sub txtConcern_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtConcern.TextChanged
        txtTankFrom.Text = txtConcern.Text
    End Sub

    Protected Sub txtLineBeforeTo_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim txtLineBeforeTo = DirectCast(sender, TextBox)
            For i As Integer = 0 To gridProduct.Rows.Count - 1

                Dim txtConnectMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLAFrom"), TextBox)
                If (txtLineBeforeTo.ClientID.Replace("txtLineBeforeTo", "") = txtConnectMLAFrom.ClientID.Replace("txtConnectMLAFrom", "")) Then
                    txtConnectMLAFrom.Text = txtLineBeforeTo.Text
                    Exit Sub
                End If
            Next
        Catch ex As Exception

        End Try

    End Sub

    Public Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        LoadBOoking()
        ViewState("Load") = "Not"
        Timer1_Tick(sender, e)
    End Sub

    Private Function CheckInput() As Boolean
        For i As Integer = 0 To gridProduct.Rows.Count - 1
            Dim txtConnectDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectDate"), TextBox)
            Dim txtConnectMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLATo"), TextBox)
            Dim txtStartActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualDate"), TextBox)
            Dim txtStartActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualTime"), TextBox)
            Dim txtStopActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualDate"), TextBox)
            Dim txtStopActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualTime"), TextBox)
            Dim txtDisDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisDate"), TextBox)
            Dim txtDisMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLATo"), TextBox)
            If (i = 0) Then
                If Not (CheckDateTime(lbBerthedDate.Text, lbBerthed.Text, txtConnectDate.Text, txtConnectMLATo.Text)) Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ข้อมูลวันเวลาในการ Connect MLA / hose ไม่ถูกต้อง');", True)
                    Return False
                End If
            End If
            If Not (CheckDateTime(txtConnectDate.Text, txtConnectMLATo.Text, txtStartActualDate.Text, txtStartActualTime.Text)) Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ข้อมูลวันเวลาในการ Started S/L, S/U ไม่ถูกต้อง');", True)
                Return False
            End If
            If Not (CheckDateTime(txtStartActualDate.Text, txtStartActualTime.Text, txtStopActualDate.Text, txtStopActualTime.Text)) Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ข้อมูลวันเวลาในการ Stopped S/L, S/U ไม่ถูกต้อง');", True)
                Return False
            End If
            If Not (CheckDateTime(txtStopActualDate.Text, txtStopActualTime.Text, txtDisDate.Text, txtDisMLATo.Text)) Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ข้อมูลวันเวลาในการ Disconnect MLA / hose ไม่ถูกต้อง');", True)
                Return False
            End If
            If (i = gridProduct.Rows.Count - 1) Then
                If (txtDisDate.Text = "") Or (txtDisMLATo.Text = "") Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรูณาทำการระบุ Disconnect MLA / hose');", True)
                    Return False
                End If
                If (txtBunkerActualDate.Text.Trim() <> "") And (txtBunkerActualTimeTo.Text.Trim() <> "") Then
                    If Not (CheckDateTime(txtDisDate.Text, txtDisMLATo.Text, txtBunkerActualDate.Text, txtBunkerActualTimeTo.Text)) Then
                        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ข้อมูลวันเวลาในการ Bunker loading ไม่ถูกต้อง');", True)
                        Return False
                    End If
                    If (txtDepartActualDate.Text.Trim() <> "") And (txtDepartAutualTime.Text.Trim() <> "") Then
                        If Not (CheckDateTime(txtBunkerActualDate.Text, txtBunkerActualTimeTo.Text, txtDepartActualDate.Text, txtDepartAutualTime.Text)) Then
                            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ข้อมูลวันเวลาในการ Departed ไม่ถูกต้อง');", True)
                            Return False
                        End If
                    End If
                Else
                    If (txtDepartActualDate.Text.Trim() <> "") And (txtDepartAutualTime.Text.Trim() <> "") Then
                        If Not (CheckDateTime(txtDisDate.Text, txtDisMLATo.Text, txtDepartActualDate.Text, txtDepartAutualTime.Text)) Then
                            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ข้อมูลวันเวลาในการ Departed ไม่ถูกต้อง');", True)
                            Return False
                        End If
                    End If
                End If
            End If
        Next
        Return True
    End Function

    Private Function CheckDateTime(ByVal _Date1 As String, ByVal _Time1 As String, ByVal _Date2 As String, ByVal _Time2 As String) As Boolean
        If (_Date1.Trim() = "") Or (_Date2.Trim() = "") Or (_Time1.Trim = "") Or (_Time2.Trim = "") Then
            Return True
        End If
        If (CInt(_Date1.Substring(6, 2) & _Date1.Substring(3, 2) & _Date1.Substring(0, 2)) > CInt(_Date2.Substring(6, 2) & _Date2.Substring(3, 2) & _Date2.Substring(0, 2))) Then
            Return False
        ElseIf (CInt(_Date1.Substring(6, 2) & _Date1.Substring(3, 2) & _Date1.Substring(0, 2)) = CInt(_Date2.Substring(6, 2) & _Date2.Substring(3, 2) & _Date2.Substring(0, 2))) Then
            If (CInt(_Time1.Split(":")(0)) > CInt(_Time2.Split(":")(0))) Then
                Return False
            ElseIf (CInt(_Time1.Split(":")(0)) = CInt(_Time2.Split(":")(0))) Then
                If (CInt(_Time1.Split(":")(1)) > CInt(_Time2.Split(":")(1))) Then
                    Return False
                End If
            End If
        End If
        Return True
    End Function

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If (True) Then
            Dim conn As New System.Data.SqlClient.SqlConnection(connString)
            Dim clsDB As New ClassDatabase
            Dim clsFc As New ClassFunction
            Dim condition As Boolean = True
            Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
            Dim User_Modify As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name")
            Dim Status As String = ""
            Dim dtStatus As DataTable = clsGet.Get_Load_Unload_Vessel(ViewState("EditBooking"))
            If (dtStatus.Rows.Count > 0) Then
                Status = dtStatus.Rows(0).Item("Status") & ""
            End If
            Dim Start As String = ""
            Application.Lock()
            conn.Open()
            tran = clsDB.BeginTran(conn)

            clsFc.DeleteLoad_Unload_All(ViewState("EditBooking"), conn, tran)
            If (clsFc.InsertLoad_Unload_Vessel(ViewState("EditBooking"), txtThirdParty.Text, txtConcern.Text, txtTankFrom.Text, txtTankTo.Text, txtFigureFrom.Text, txtLabFrom.Text, txtSamplingFrom.Text, txtSamplingTo.Text, txtLabafter.Text, txtTankafterFrom.Text, txtTankafterTo.Text, txtFigureafter.Text, txtDocument.Text, txtBunker.Text, lbTruckTime.Text, lbBunkerStandardDate.Text, lbBunkerStandard.Text, txtBunkerActualDate.Text, txtBunkerActualTime.Text, txtBunkerActualTimeTo.Text, lbDepartStandardDate.Text, lbDepartStandard.Text, txtDepartActualDate.Text, txtDepartAutualTime.Text, lbTugBefore.Text, lbTugAfter.Text, txtNORTender.Text, txtNORTenderTime.Text, Status, conn, tran) > 0) Then
                For i As Integer = 0 To gridProduct.Rows.Count - 1

                    Dim txtLineBeforeFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeFrom"), TextBox)
                    Dim txtLineBeforeTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeTo"), TextBox)
                    Dim txtConnectDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectDate"), TextBox)
                    Dim txtConnectMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLAFrom"), TextBox)
                    Dim txtConnectMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLATo"), TextBox)
                    Dim lbStartStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandardDate"), Label)
                    Dim lbStartStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandard"), Label)
                    Dim txtStartActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualDate"), TextBox)
                    Dim txtStartActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualTime"), TextBox)
                    Dim lbStopStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandardDate"), Label)
                    Dim lbStopStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandard"), Label)
                    Dim txtStopActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualDate"), TextBox)
                    Dim txtStopActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualTime"), TextBox)
                    Dim txtLineafterFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterFrom"), TextBox)
                    Dim txtLineafterTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterTo"), TextBox)
                    Dim txtDisDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisDate"), TextBox)
                    Dim txtDisMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLAFrom"), TextBox)
                    Dim txtDisMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLATo"), TextBox)

                    If (Start = "") Then
                        Start = txtStartActualDate.Text & " " & txtStartActualTime.Text
                    End If
                    If lbDirection.Text = "LOADING" Then
                        Dim txtBLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLM3_Load"), TextBox)
                        Dim txtBLMT_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLMT_Load"), TextBox)
                        Dim txtSLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLM3_Load"), TextBox)
                        Dim txtSLMT_LOad As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLMT_LOad"), TextBox)
                        Dim txtAPIShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore_Load"), TextBox)
                        Dim txtViscosityShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscosityShore_Load"), TextBox)
                        Dim txtAPIShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip_Load"), TextBox)
                        Dim txtViscositShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscositShip_Load"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLM3_Load.Text, txtBLMT_Load.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLM3_Load.Text, txtSLMT_LOad.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore_Load.Text, txtAPIShip_Load.Text, txtViscosityShore_Load.Text, txtViscositShip_Load.Text, "", "", "", "", txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    Else
                        Dim txtBLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFig"), TextBox)
                        Dim txtBLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFigMT"), TextBox)
                        Dim txtSLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFig"), TextBox)
                        Dim txtSLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFigMT"), TextBox)
                        Dim txtAPIShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore"), TextBox)
                        Dim txtAPIShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip"), TextBox)
                        Dim txtVisShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShore"), TextBox)
                        Dim txtVisShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShip"), TextBox)

                        Dim txtSUFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFig"), TextBox)
                        Dim txtSUFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFigMT"), TextBox)
                        Dim txtShoreReceive As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceive"), TextBox)
                        Dim txtShoreReceiveMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceiveMT"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLFig.Text, txtBLFigMT.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLFig.Text, txtSLFigMT.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore.Text, txtAPIShip.Text, txtVisShore.Text, txtVisShip.Text, txtSUFig.Text, txtSUFigMT.Text, txtShoreReceive.Text, txtShoreReceiveMT.Text, txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    End If
                Next

                'If (txtDepartActualDate.Text.Trim() <> "") And (txtDepartAutualTime.Text.Trim() <> "") Then
                '    If (clsFc.UpdateBookingStatusOneField(ViewState("EditBooking"), "OA", conn, tran) < 1) Then
                '        condition = False
                '    End If
                'End If

                Dim dtDelay As DataTable = Session("Delay")
                For Each dr As DataRow In dtDelay.Rows
                    If (clsFc.InsertLoad_Unload_Delay(ViewState("EditBooking"), dr.Item("Date_From"), dr.Item("Date_To"), dr.Item("Time_From"), dr.Item("Time_To"), dr.Item("Cause_Delay"), dr.Item("Delay_Time"), dr.Item("Cause_Code"), conn, tran) < 1) Then
                        condition = False
                        Exit For
                    End If
                Next
                If (clsFc.InsertLoad_Unload_Addition(ViewState("EditBooking"), "0", "0", "0", "0", txtWater.Text, "0", txtDisposal.Text, txtBunker_FO.Text, txtBunker_DO.Text, "0", txtExcise.Text, txtNitrogen.Text, txtElectic.Text, "0", "00:00", "00:00", "", "", conn, tran) < 1) Then
                    condition = False
                End If
                For i As Integer = 0 To gridStock.Rows.Count - 1
                    Dim txtCount As TextBox = CType(gridStock.Rows(i).FindControl("txtCount"), TextBox)
                    Dim chk As CheckBox = CType(gridStock.Rows(i).FindControl("chkStock"), CheckBox)
                    Dim statusss As String = ""
                    If (chk.Checked) Then
                        statusss = "Y"
                    Else
                        statusss = "N"
                    End If
                    If (txtCount.Text = "") Then
                        txtCount.Text = "0"
                    End If
                    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), gridStock.DataKeys(i).Values("Stock_Code"), gridStock.DataKeys(i).Values("Grade"), gridStock.DataKeys(i).Values("Brand"), txtCount.Text, statusss, conn, tran) < 1) Then
                        condition = False
                    End If
                Next
                'Dim ds As DataSet = Session("_STOCK")
                'For Each drstock As DataRow In ds.Tables(0).Rows
                '    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), drstock.Item("Stock_Code"), drstock.Item("Grade"), drstock.Item("Brand"), drstock.Item("Count"), conn, tran) < 1) Then
                '        condition = False
                '    End If
                'Next
            Else
                condition = False
            End If

            If (condition) Then
                clsDB.CommitTran(tran)
                ' LoadBOoking()
                GenDateLiteral()
                GetPTOL()
                ViewState("Load") = "Not"
                If Not CBool(ViewState("Start")) Then
                    Dim str As String = ""
                    Dim dtBOoking As DataTable = clsGet.Get_BookingOneRecord(ViewState("EditBooking")).Tables(0)
                    Dim dtLogSheet As DataTable = clsGet.Get_Booking_LogSheet_In(ViewState("EditBooking"))
                    Dim Berth As String = ""
                    If (dtLogSheet.Rows.Count > 0) Then
                        Berth = dtLogSheet.Rows(0).Item("Berthing_Date") & " " & dtLogSheet.Rows(0).Item("Berthing_TimeTo")
                    End If
                    str = GenBody("เริ่มดำเนินการขนถ่าย", ViewState("EditBooking"), dtBOoking.Rows(0).Item("MAgent_no") & "-" & dtBOoking.Rows(0).Item("MAgent_name"), dtBOoking.Rows(0).Item("Vehicle_no") & "-" & dtBOoking.Rows(0).Item("Vehicle_Text"), dtBOoking.Rows(0).Item("Date_From") & "-" & dtBOoking.Rows(0).Item("Date_To"), Berth, Start, "", "")
                    SendMail(ViewState("EditBooking"), "CUSTOMER", str)
                    ViewState("Start") = True
                End If
                Timer1_Tick(sender, e)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('บันทึกข้อมูลสำเร็จ');", True)
            Else
                clsDB.RollBackTran(tran)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เกิดความผิดพลาดในการบันทึก');", True)
            End If
            Application.UnLock()
            conn.Dispose()
        End If

    End Sub

    Private Sub btnDelay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelay.Click
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " document.getElementById('ctl00_contentplaceholder1_EditDelay').src = '../FormPopup/CauseOfDelay.aspx';", True)
        Session("DelayEdit") = Nothing
        ModalPopupExtender4.Show()
    End Sub

    Private Sub btnDelayLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelayLoad.Click
        'ทำการโหลด Remark Delay
        System.Threading.Thread.Sleep(750)
        gridDelay.DataSource = Session("Delay")
        gridDelay.DataBind()
    End Sub

    Private Function CreateTabelDelay() As DataTable
        Dim Dt As New DataTable
        Dt.Columns.Add("Delay_DateTime", GetType(String))
        Dt.Columns.Add("Cause_Delay", GetType(String))
        Dt.Columns.Add("Cause_Code", GetType(String))
        Dt.Columns.Add("Delay_Time", GetType(String))
        Dt.Columns.Add("Date_From", GetType(String))
        Dt.Columns.Add("Date_To", GetType(String))
        Dt.Columns.Add("Time_From", GetType(String))
        Dt.Columns.Add("Time_To", GetType(String))
        Dt.AcceptChanges()
        Return Dt
    End Function

    Private Sub gridDelay_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridDelay.RowCommand
        Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
        If e.CommandName = "cmdedit" Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " document.getElementById('ctl00_contentplaceholder1_EditDelay').src = '../FormPopup/CauseOfDelay.aspx';", True)
            Session("DelayEdit") = Index
            ModalPopupExtender4.Show()
        ElseIf (e.CommandName = "cmddelete") Then
            Dim dt As DataTable = Session("Delay")
            dt.Rows(Index).Delete()
            dt.AcceptChanges()
            Session("Delay") = dt
        End If
    End Sub

    'Private Sub imgBefore_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgBefore.Click
    '    Session("TugEvent") = "Before"
    '    Session("TugValue") = lbTugBefore.Text
    '    ModalPopupExtender1.Show()
    'End Sub

    'Private Sub imgAfter_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgAfter.Click
    '    Session("TugEvent") = "After"
    '    Session("TugValue") = lbTugAfter.Text
    '    ModalPopupExtender1.Show()
    'End Sub

    Private Sub btnTugLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTugLoad.Click
        Dim dt As DataTable
        If Not (Session("TugBeforeLoading") Is Nothing) Then
            dt = Session("TugBeforeLoading")
            Dim str As String = ""
            For Each dr As DataRow In dt.Rows
                If (dr.Item("TugName") <> "") Then
                    If (str = "") Then
                        str = dr.Item("TugName")
                    Else
                        str &= "," & dr.Item("TugName")
                    End If
                End If
            Next
            lbTugBefore.Text = str
        End If
        If Not (Session("TugAfterLoading") Is Nothing) Then
            dt = Session("TugAfterLoading")
            Dim str As String = ""
            For Each dr As DataRow In dt.Rows
                If (dr.Item("TugName") <> "") Then
                    If (str = "") Then
                        str = dr.Item("TugName")
                    Else
                        str &= "," & dr.Item("TugName")
                    End If
                End If
            Next
            lbTugAfter.Text = str
        End If
    End Sub

    Private Sub gridDelay_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gridDelay.RowEditing

    End Sub

    Private Sub btnCheck_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheck.Click
        If (CheckInput()) Then
            Dim conn As New System.Data.SqlClient.SqlConnection(connString)
            Dim clsDB As New ClassDatabase
            Dim clsFc As New ClassFunction
            Dim condition As Boolean = True
            Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
            Dim User_Modify As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name")
            Application.Lock()
            conn.Open()
            Dim A_Code As String = clsDB.GeneratorID(conn, "Action_Operation")
            tran = clsDB.BeginTran(conn)
            clsFc.DeleteLoad_Unload_All(ViewState("EditBooking"), conn, tran)
            If (clsFc.InsertLoad_Unload_Vessel(ViewState("EditBooking"), txtThirdParty.Text, txtConcern.Text, txtTankFrom.Text, txtTankTo.Text, txtFigureFrom.Text, txtLabFrom.Text, txtSamplingFrom.Text, txtSamplingTo.Text, txtLabafter.Text, txtTankafterFrom.Text, txtTankafterTo.Text, txtFigureafter.Text, txtDocument.Text, txtBunker.Text, lbTruckTime.Text, lbBunkerStandardDate.Text, lbBunkerStandard.Text, txtBunkerActualDate.Text, txtBunkerActualTime.Text, txtBunkerActualTimeTo.Text, lbDepartStandardDate.Text, lbDepartStandard.Text, txtDepartActualDate.Text, txtDepartAutualTime.Text, lbTugBefore.Text, lbTugAfter.Text, txtNORTender.Text, txtNORTenderTime.Text, "C", conn, tran) > 0) Then
                For i As Integer = 0 To gridProduct.Rows.Count - 1

                    Dim txtLineBeforeFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeFrom"), TextBox)
                    Dim txtLineBeforeTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeTo"), TextBox)
                    Dim txtConnectDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectDate"), TextBox)
                    Dim txtConnectMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLAFrom"), TextBox)
                    Dim txtConnectMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLATo"), TextBox)
                    Dim lbStartStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandardDate"), Label)
                    Dim lbStartStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandard"), Label)
                    Dim txtStartActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualDate"), TextBox)
                    Dim txtStartActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualTime"), TextBox)
                    Dim lbStopStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandardDate"), Label)
                    Dim lbStopStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandard"), Label)
                    Dim txtStopActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualDate"), TextBox)
                    Dim txtStopActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualTime"), TextBox)
                    Dim txtLineafterFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterFrom"), TextBox)
                    Dim txtLineafterTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterTo"), TextBox)
                    Dim txtDisDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisDate"), TextBox)
                    Dim txtDisMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLAFrom"), TextBox)
                    Dim txtDisMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLATo"), TextBox)

                    If lbDirection.Text = "LOADING" Then
                        Dim txtBLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLM3_Load"), TextBox)
                        Dim txtBLMT_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLMT_Load"), TextBox)
                        Dim txtSLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLM3_Load"), TextBox)
                        Dim txtSLMT_LOad As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLMT_LOad"), TextBox)
                        Dim txtAPIShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore_Load"), TextBox)
                        Dim txtViscosityShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscosityShore_Load"), TextBox)
                        Dim txtAPIShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip_Load"), TextBox)
                        Dim txtViscositShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscositShip_Load"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLM3_Load.Text, txtBLMT_Load.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLM3_Load.Text, txtSLMT_LOad.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore_Load.Text, txtAPIShip_Load.Text, txtViscosityShore_Load.Text, txtViscositShip_Load.Text, "", "", "", "", txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    Else
                        Dim txtBLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFig"), TextBox)
                        Dim txtBLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFigMT"), TextBox)
                        Dim txtSLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFig"), TextBox)
                        Dim txtSLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFigMT"), TextBox)
                        Dim txtAPIShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore"), TextBox)
                        Dim txtAPIShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip"), TextBox)
                        Dim txtVisShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShore"), TextBox)
                        Dim txtVisShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShip"), TextBox)

                        Dim txtSUFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFig"), TextBox)
                        Dim txtSUFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFigMT"), TextBox)
                        Dim txtShoreReceive As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceive"), TextBox)
                        Dim txtShoreReceiveMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceiveMT"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLFig.Text, txtBLFigMT.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLFig.Text, txtSLFigMT.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore.Text, txtAPIShip.Text, txtVisShore.Text, txtVisShip.Text, txtSUFig.Text, txtSUFigMT.Text, txtShoreReceive.Text, txtShoreReceiveMT.Text, txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    End If
                Next

                Dim dtDelay As DataTable = Session("Delay")
                For Each dr As DataRow In dtDelay.Rows
                    If (clsFc.InsertLoad_Unload_Delay(ViewState("EditBooking"), dr.Item("Date_From"), dr.Item("Date_To"), dr.Item("Time_From"), dr.Item("Time_To"), dr.Item("Cause_Delay"), dr.Item("Delay_Time"), dr.Item("Cause_Code"), conn, tran) < 1) Then
                        condition = False
                        Exit For
                    End If
                Next
                If (clsFc.InsertLoad_Unload_Addition(ViewState("EditBooking"), "0", "0", "0", "0", txtWater.Text, "0", txtDisposal.Text, txtBunker_FO.Text, txtBunker_DO.Text, "0", txtExcise.Text, txtNitrogen.Text, txtElectic.Text, "0", "00:00", "00:00", "", "", conn, tran) < 1) Then
                    condition = False
                End If
                For i As Integer = 0 To gridStock.Rows.Count - 1
                    Dim txtCount As TextBox = CType(gridStock.Rows(i).FindControl("txtCount"), TextBox)
                    Dim chk As CheckBox = CType(gridStock.Rows(i).FindControl("chkStock"), CheckBox)
                    Dim statusss As String = ""
                    If (chk.Checked) Then
                        statusss = "Y"
                    Else
                        statusss = "N"
                    End If
                    If (txtCount.Text = "") Then
                        txtCount.Text = "0"
                    End If
                    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), gridStock.DataKeys(i).Values("Stock_Code"), gridStock.DataKeys(i).Values("Grade"), gridStock.DataKeys(i).Values("Brand"), txtCount.Text, statusss, conn, tran) < 1) Then
                        condition = False
                    End If
                Next
                'Dim ds As DataSet = Session("_STOCK")
                'For Each drstock As DataRow In ds.Tables(0).Rows
                '    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), drstock.Item("Stock_Code"), drstock.Item("Grade"), drstock.Item("Brand"), drstock.Item("Count"), conn, tran) < 1) Then
                '        condition = False
                '    End If
                'Next
            Else
                condition = False
            End If
            'If (clsFc.UPDATELoad_Unload_Vessel_Status(ViewState("EditBooking"), "C", conn, tran) < 1) Then
            '    condition = False
            'End If
            If (clsFc.InsertAction_Operation(A_Code, ViewState("EditBooking"), "Check Data By", DateTime.Now.ToString("dd MMMM yyyy", New CultureInfo("en-US")), DateTime.Now.ToString("HH:mm"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Name"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name"), "", conn, tran) < 1) Then
                condition = False
            End If
            If (condition) Then
                clsDB.CommitTran(tran)
                LoadBOoking()
                ViewState("Load") = "Not"
                Timer1_Tick(sender, e)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('บันทึกการตรวจสอบข้อมูลสำเร็จ');", True)
            Else
                clsDB.RollBackTran(tran)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เกิดความผิดพลาดในการบันทึก');", True)
            End If
            Application.UnLock()
            conn.Dispose()
        End If

    End Sub

    Private Sub btnApprove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApprove.Click
        If (CheckInput()) Then
            Dim conn As New System.Data.SqlClient.SqlConnection(connString)
            Dim clsDB As New ClassDatabase
            Dim clsFc As New ClassFunction
            Dim condition As Boolean = True
            Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
            Dim User_Modify As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name")
            Dim ds As DataSet = Session("UserData")
            Dim User_Create As String = ds.Tables(0).Rows(0).Item("User_Name").ToString() & " " & DateTime.Now.ToString("dd MMM yyyy HH:mm:ss", New CultureInfo("en-US"))
            Dim dtLogSheet As DataTable = clsGet.Get_Booking_LogSheet_Out(ViewState("EditBooking"))
            Application.Lock()
            conn.Open()
            Dim A_Code As String = clsDB.GeneratorID(conn, "Action_Operation")
            tran = clsDB.BeginTran(conn)
            clsFc.DeleteLoad_Unload_All(ViewState("EditBooking"), conn, tran)
            If (clsFc.InsertLoad_Unload_Vessel(ViewState("EditBooking"), txtThirdParty.Text, txtConcern.Text, txtTankFrom.Text, txtTankTo.Text, txtFigureFrom.Text, txtLabFrom.Text, txtSamplingFrom.Text, txtSamplingTo.Text, txtLabafter.Text, txtTankafterFrom.Text, txtTankafterTo.Text, txtFigureafter.Text, txtDocument.Text, txtBunker.Text, lbTruckTime.Text, lbBunkerStandardDate.Text, lbBunkerStandard.Text, txtBunkerActualDate.Text, txtBunkerActualTime.Text, txtBunkerActualTimeTo.Text, lbDepartStandardDate.Text, lbDepartStandard.Text, txtDepartActualDate.Text, txtDepartAutualTime.Text, lbTugBefore.Text, lbTugAfter.Text, txtNORTender.Text, txtNORTenderTime.Text, "A", conn, tran) > 0) Then
                For i As Integer = 0 To gridProduct.Rows.Count - 1

                    Dim txtLineBeforeFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeFrom"), TextBox)
                    Dim txtLineBeforeTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeTo"), TextBox)
                    Dim txtConnectDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectDate"), TextBox)
                    Dim txtConnectMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLAFrom"), TextBox)
                    Dim txtConnectMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLATo"), TextBox)
                    Dim lbStartStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandardDate"), Label)
                    Dim lbStartStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandard"), Label)
                    Dim txtStartActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualDate"), TextBox)
                    Dim txtStartActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualTime"), TextBox)
                    Dim lbStopStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandardDate"), Label)
                    Dim lbStopStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandard"), Label)
                    Dim txtStopActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualDate"), TextBox)
                    Dim txtStopActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualTime"), TextBox)
                    Dim txtLineafterFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterFrom"), TextBox)
                    Dim txtLineafterTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterTo"), TextBox)
                    Dim txtDisDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisDate"), TextBox)
                    Dim txtDisMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLAFrom"), TextBox)
                    Dim txtDisMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLATo"), TextBox)

                    If lbDirection.Text = "LOADING" Then
                        Dim txtBLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLM3_Load"), TextBox)
                        Dim txtBLMT_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLMT_Load"), TextBox)
                        Dim txtSLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLM3_Load"), TextBox)
                        Dim txtSLMT_LOad As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLMT_LOad"), TextBox)
                        Dim txtAPIShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore_Load"), TextBox)
                        Dim txtViscosityShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscosityShore_Load"), TextBox)
                        Dim txtAPIShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip_Load"), TextBox)
                        Dim txtViscositShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscositShip_Load"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLM3_Load.Text, txtBLMT_Load.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLM3_Load.Text, txtSLMT_LOad.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore_Load.Text, txtAPIShip_Load.Text, txtViscosityShore_Load.Text, txtViscositShip_Load.Text, "", "", "", "", txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    Else
                        Dim txtBLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFig"), TextBox)
                        Dim txtBLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFigMT"), TextBox)
                        Dim txtSLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFig"), TextBox)
                        Dim txtSLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFigMT"), TextBox)
                        Dim txtAPIShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore"), TextBox)
                        Dim txtAPIShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip"), TextBox)
                        Dim txtVisShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShore"), TextBox)
                        Dim txtVisShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShip"), TextBox)

                        Dim txtSUFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFig"), TextBox)
                        Dim txtSUFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFigMT"), TextBox)
                        Dim txtShoreReceive As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceive"), TextBox)
                        Dim txtShoreReceiveMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceiveMT"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLFig.Text, txtBLFigMT.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLFig.Text, txtSLFigMT.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore.Text, txtAPIShip.Text, txtVisShore.Text, txtVisShip.Text, txtSUFig.Text, txtSUFigMT.Text, txtShoreReceive.Text, txtShoreReceiveMT.Text, txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    End If
                Next

                Dim dtDelay As DataTable = Session("Delay")
                For Each dr As DataRow In dtDelay.Rows
                    If (clsFc.InsertLoad_Unload_Delay(ViewState("EditBooking"), dr.Item("Date_From"), dr.Item("Date_To"), dr.Item("Time_From"), dr.Item("Time_To"), dr.Item("Cause_Delay"), dr.Item("Delay_Time"), dr.Item("Cause_Code"), conn, tran) < 1) Then
                        condition = False
                        Exit For
                    End If
                Next
                If (clsFc.InsertLoad_Unload_Addition(ViewState("EditBooking"), "0", "0", "0", "0", txtWater.Text, "0", txtDisposal.Text, txtBunker_FO.Text, txtBunker_DO.Text, "0", txtExcise.Text, txtNitrogen.Text, txtElectic.Text, "0", "00:00", "00:00", "", "", conn, tran) < 1) Then
                    condition = False
                End If
                For i As Integer = 0 To gridStock.Rows.Count - 1
                    Dim txtCount As TextBox = CType(gridStock.Rows(i).FindControl("txtCount"), TextBox)
                    Dim chk As CheckBox = CType(gridStock.Rows(i).FindControl("chkStock"), CheckBox)
                    Dim statusss As String = ""
                    If (chk.Checked) Then
                        statusss = "Y"
                    Else
                        statusss = "N"
                    End If
                    If (txtCount.Text = "") Then
                        txtCount.Text = "0"
                    End If
                    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), gridStock.DataKeys(i).Values("Stock_Code"), gridStock.DataKeys(i).Values("Grade"), gridStock.DataKeys(i).Values("Brand"), txtCount.Text, statusss, conn, tran) < 1) Then
                        condition = False
                    End If
                Next
                'Dim ds As DataSet = Session("_STOCK")
                'For Each drstock As DataRow In ds.Tables(0).Rows
                '    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), drstock.Item("Stock_Code"), drstock.Item("Grade"), drstock.Item("Brand"), drstock.Item("Count"), conn, tran) < 1) Then
                '        condition = False
                '    End If
                'Next
            Else
                condition = False
            End If
            'If (clsFc.UPDATELoad_Unload_Vessel_Status(ViewState("EditBooking"), "A", conn, tran) < 1) Then
            '    condition = False
            'End If
            If (clsFc.InsertAction_Operation(A_Code, ViewState("EditBooking"), "Approve Data By", DateTime.Now.ToString("dd MMMM yyyy", New CultureInfo("en-US")), DateTime.Now.ToString("HH:mm"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Name"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name"), "", conn, tran) < 1) Then
                condition = False
            End If
            If dtLogSheet.Rows.Count > 0 Then
                If (dtLogSheet.Rows(0).Item("Status") & "" = "A") Then
                    If (clsFc.UpdateBookingStatusOneField(ViewState("EditBooking"), "OA", conn, tran) < 1) Then
                        condition = False
                    End If
                End If
            End If
            For i As Integer = 0 To gridStock.Rows.Count - 1
                Dim txtCount As TextBox = CType(gridStock.Rows(i).FindControl("txtCount"), TextBox)
                Dim chk As CheckBox = CType(gridStock.Rows(i).FindControl("chkStock"), CheckBox)
                If (txtCount.Text = "") Then
                    txtCount.Text = "0"
                End If
                If (chk.Checked) Then
                    If (clsFc.Update_StockValue("C", gridStock.DataKeys(i).Values("Stock_Code"), txtCount.Text, conn, tran) > 0) Then
                        If (clsFc.Insert_StockAdd_Remove(gridStock.DataKeys(i).Values("Stock_Code"), "C", txtCount.Text, User_Create, ViewState("EditBooking"), "Cut Stock By Ship Performance", DateTime.Now.ToString("yyyyMMdd", New CultureInfo("en-US")), conn, tran) < 1) Then
                            condition = False
                        End If
                    Else
                        condition = False
                    End If
                End If

            Next

            If (condition) Then
                clsDB.CommitTran(tran)
                Dim SEND As String = ""
                Dim str As String = ""
                Dim dtBOoking As DataTable = clsGet.Get_BookingOneRecord(ViewState("EditBooking")).Tables(0)
                If dtLogSheet.Rows.Count > 0 Then
                    Dim dtLogSheetIn As DataTable = clsGet.Get_Booking_LogSheet_In(ViewState("EditBooking"))
                    Dim Berth As String = ""
                    Dim Depart As String = dtLogSheet.Rows(0).Item("Last_Date") & " " & dtLogSheet.Rows(0).Item("Last_Time")
                    If (dtLogSheetIn.Rows.Count > 0) Then
                        Berth = dtLogSheetIn.Rows(0).Item("Berthing_Date") & " " & dtLogSheetIn.Rows(0).Item("Berthing_TimeTo")
                    End If
                    Dim dtLoad As DataTable = clsGet.Get_Load_Unload_Product_PTOL(ViewState("EditBooking"), "", "")
                    Dim Dis_Date As String = ""
                    Dim Dis_Time As String = ""
                    Dim Con_Date As String = ""
                    Dim Con_Time As String = ""
                    For Each dl As DataRow In dtLoad.Rows
                        Try
                            If (Dis_Date = "") Then
                                Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                Dis_Time = dl.Item("LU_Disconnect_To") & ""
                            End If
                            Dim _DD As String = Dis_Date.Substring(0, 2) & " " & GetNameMonth(Dis_Date.Substring(3, 2)) & " " & CInt("20" & Dis_Date.Substring(6, 2))
                            Dim _D2 As String = dl.Item("LU_Disconnect_Date").Substring(0, 2) & " " & GetNameMonth(dl.Item("LU_Disconnect_Date").Substring(3, 2)) & " " & CInt("20" & dl.Item("LU_Disconnect_Date").Substring(6, 2))
                            If (CDate(ClassFunctionGetData.CDateT(_DD)) < CDate(ClassFunctionGetData.CDateT(_D2))) Then
                                Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                Dis_Time = dl.Item("LU_Disconnect_To") & ""
                            ElseIf (CDate(ClassFunctionGetData.CDateT(_DD)) = CDate(ClassFunctionGetData.CDateT(_D2))) Then
                                If (CInt(Dis_Time.Split(":")(0)) < CInt(dl.Item("LU_Disconnect_To").ToString.Split(":")(0))) Then
                                    Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                    Dis_Time = dl.Item("LU_Disconnect_To") & ""
                                ElseIf (CInt(Dis_Time.Split(":")(0)) = CInt(dl.Item("LU_Disconnect_To").ToString.Split(":")(0))) Then
                                    Try
                                        If (CInt(Dis_Time.Split(":")(1)) < CInt(dl.Item("LU_Disconnect_To").ToString.Split(":")(1))) Then
                                            Dis_Date = dl.Item("LU_Disconnect_Date") & ""
                                            Dis_Time = dl.Item("LU_Disconnect_To") & ""
                                        End If
                                    Catch ex As Exception

                                    End Try
                                End If
                            End If

                            If (Con_Date = "") Then
                                Con_Date = dl.Item("LU_Connect_Date") & ""
                                Con_Time = dl.Item("LU_Connect_To") & ""
                            End If
                            _DD = Con_Date.Substring(0, 2) & " " & GetNameMonth(Con_Date.Substring(3, 2)) & " " & CInt("20" & Con_Date.Substring(6, 2))
                            _D2 = dl.Item("LU_Connect_Date").Substring(0, 2) & " " & GetNameMonth(dl.Item("LU_Connect_Date").Substring(3, 2)) & " " & CInt("20" & dl.Item("LU_Connect_Date").Substring(6, 2))
                            If (CDate(ClassFunctionGetData.CDateT(_DD)) < CDate(ClassFunctionGetData.CDateT(_D2))) Then
                                Con_Date = dl.Item("LU_Connect_Date") & ""
                                Con_Time = dl.Item("LU_Connect_To") & ""
                            ElseIf (CDate(ClassFunctionGetData.CDateT(_DD)) = CDate(ClassFunctionGetData.CDateT(_D2))) Then
                                If (CInt(Con_Time.Split(":")(0)) < CInt(dl.Item("LU_Connect_To").ToString.Split(":")(0))) Then
                                    Con_Date = dl.Item("LU_Connect_Date") & ""
                                    Con_Time = dl.Item("LU_Connect_To") & ""
                                ElseIf (CInt(Con_Time.Split(":")(0)) = CInt(dl.Item("LU_Connect_To").ToString.Split(":")(0))) Then
                                    Try
                                        If (CInt(Con_Time.Split(":")(1)) < CInt(dl.Item("LU_Connect_To").ToString.Split(":")(1))) Then
                                            Con_Date = dl.Item("LU_Connect_Date") & ""
                                            Con_Time = dl.Item("LU_Connect_To") & ""
                                        End If
                                    Catch ex As Exception

                                    End Try
                                End If
                            End If
                        Catch ex As Exception

                        End Try

                    Next


                    If (dtLogSheet.Rows(0).Item("Status") & "" = "A") Then
                        'OA
                        SEND = "MARKETING"
                        str = GenBody("ดำเนินขนถ่ายสินค้าเสร็จสมบูรณ์ และ เรือออกจากท่าเรือแล้ว รอการคำนวณค่าใช้บริการจากระบบ iPORT", ViewState("EditBooking"), dtBOoking.Rows(0).Item("MAgent_no") & "-" & dtBOoking.Rows(0).Item("MAgent_name"), dtBOoking.Rows(0).Item("Vehicle_no") & "-" & dtBOoking.Rows(0).Item("Vehicle_Text"), dtBOoking.Rows(0).Item("Date_From") & "-" & dtBOoking.Rows(0).Item("Date_To"), Berth, Con_Date & " " & Con_Time, Dis_Date & " " & Dis_Time, Depart)
                    Else
                        SEND = "PTO"
                        str = GenBody("ดำเนินขนถ่ายสินค้าเสร็จสมบูรณ์", ViewState("EditBooking"), dtBOoking.Rows(0).Item("MAgent_no") & "-" & dtBOoking.Rows(0).Item("MAgent_name"), dtBOoking.Rows(0).Item("Vehicle_no") & "-" & dtBOoking.Rows(0).Item("Vehicle_Text"), dtBOoking.Rows(0).Item("Date_From") & "-" & dtBOoking.Rows(0).Item("Date_To"), Berth, Con_Date & " " & Con_Time, Dis_Date & " " & Dis_Time, Depart)
                    End If
                End If
                LoadBOoking()
                ViewState("Load") = "Not"
                Timer1_Tick(sender, e)
                Dim dtCheck As DataTable = clsGet.Check_Stock_Empty()
                SendMail(ViewState("EditBooking"), SEND, str)
                Dim strALert As String = "บันทึกการอนุมัติข้อมูลสำเร็จ"
                If (dtCheck.Rows.Count > 0) Then
                    strALert &= "\n\rรายการ Additional ที่ติดลบใน Stock กรุณาทำการเพิ่ม"
                    Dim count As Integer = 0
                    For Each dr As DataRow In dtCheck.Rows
                        count += 1
                        strALert &= "\n\r" & count.ToString() & ". " & dr.Item("Grade") & "(" & dr.Item("Brand") & ")" & " จำนวน " & dr.Item("Amount")
                    Next
                End If
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('" & strALert & "');", True)
                '  ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('x');", True)
            Else
                clsDB.RollBackTran(tran)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เกิดความผิดพลาดในการบันทึก');", True)
            End If
            Application.UnLock()
            conn.Dispose()
        End If

    End Sub

    Private Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
        If (CheckInput()) Then
            Dim conn As New System.Data.SqlClient.SqlConnection(connString)
            Dim clsDB As New ClassDatabase
            Dim clsFc As New ClassFunction
            Dim condition As Boolean = True
            Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
            Dim User_Modify As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name")
            Application.Lock()
            conn.Open()
            Dim A_Code As String = clsDB.GeneratorID(conn, "Action_Operation")
            Dim start As String = ""
            tran = clsDB.BeginTran(conn)
            clsFc.DeleteLoad_Unload_All(ViewState("EditBooking"), conn, tran)
            If (clsFc.InsertLoad_Unload_Vessel(ViewState("EditBooking"), txtThirdParty.Text, txtConcern.Text, txtTankFrom.Text, txtTankTo.Text, txtFigureFrom.Text, txtLabFrom.Text, txtSamplingFrom.Text, txtSamplingTo.Text, txtLabafter.Text, txtTankafterFrom.Text, txtTankafterTo.Text, txtFigureafter.Text, txtDocument.Text, txtBunker.Text, lbTruckTime.Text, lbBunkerStandardDate.Text, lbBunkerStandard.Text, txtBunkerActualDate.Text, txtBunkerActualTime.Text, txtBunkerActualTimeTo.Text, lbDepartStandardDate.Text, lbDepartStandard.Text, txtDepartActualDate.Text, txtDepartAutualTime.Text, lbTugBefore.Text, lbTugAfter.Text, txtNORTender.Text, txtNORTenderTime.Text, "S", conn, tran) > 0) Then
                For i As Integer = 0 To gridProduct.Rows.Count - 1

                    Dim txtLineBeforeFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeFrom"), TextBox)
                    Dim txtLineBeforeTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineBeforeTo"), TextBox)
                    Dim txtConnectDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectDate"), TextBox)
                    Dim txtConnectMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLAFrom"), TextBox)
                    Dim txtConnectMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtConnectMLATo"), TextBox)
                    Dim lbStartStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandardDate"), Label)
                    Dim lbStartStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStartStandard"), Label)
                    Dim txtStartActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualDate"), TextBox)
                    Dim txtStartActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStartActualTime"), TextBox)
                    Dim lbStopStandardDate As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandardDate"), Label)
                    Dim lbStopStandard As Label = CType(gridProduct.Rows(i).FindControl("lbStopStandard"), Label)
                    Dim txtStopActualDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualDate"), TextBox)
                    Dim txtStopActualTime As TextBox = CType(gridProduct.Rows(i).FindControl("txtStopActualTime"), TextBox)
                    Dim txtLineafterFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterFrom"), TextBox)
                    Dim txtLineafterTo As TextBox = CType(gridProduct.Rows(i).FindControl("txtLineafterTo"), TextBox)
                    Dim txtDisDate As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisDate"), TextBox)
                    Dim txtDisMLAFrom As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLAFrom"), TextBox)
                    Dim txtDisMLATo As TextBox = CType(gridProduct.Rows(i).FindControl("txtDisMLATo"), TextBox)
                    If (start = "") Then
                        Try
                            start = txtStartActualDate.Text
                            start = start.Substring(0, 2) & " " & GetNameMonth(start.Substring(3, 2)) & " " & CInt("20" & start.Substring(6, 2))
                            start &= " " & txtStartActualTime.Text
                        Catch ex As Exception

                        End Try
                    End If
                    If lbDirection.Text = "LOADING" Then
                        Dim txtBLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLM3_Load"), TextBox)
                        Dim txtBLMT_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLMT_Load"), TextBox)
                        Dim txtSLM3_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLM3_Load"), TextBox)
                        Dim txtSLMT_LOad As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLMT_LOad"), TextBox)
                        Dim txtAPIShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore_Load"), TextBox)
                        Dim txtViscosityShore_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscosityShore_Load"), TextBox)
                        Dim txtAPIShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip_Load"), TextBox)
                        Dim txtViscositShip_Load As TextBox = CType(gridProduct.Rows(i).FindControl("txtViscositShip_Load"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLM3_Load.Text, txtBLMT_Load.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLM3_Load.Text, txtSLMT_LOad.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore_Load.Text, txtAPIShip_Load.Text, txtViscosityShore_Load.Text, txtViscositShip_Load.Text, "", "", "", "", txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    Else
                        Dim txtBLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFig"), TextBox)
                        Dim txtBLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtBLFigMT"), TextBox)
                        Dim txtSLFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFig"), TextBox)
                        Dim txtSLFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSLFigMT"), TextBox)
                        Dim txtAPIShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShore"), TextBox)
                        Dim txtAPIShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtAPIShip"), TextBox)
                        Dim txtVisShore As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShore"), TextBox)
                        Dim txtVisShip As TextBox = CType(gridProduct.Rows(i).FindControl("txtVisShip"), TextBox)

                        Dim txtSUFig As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFig"), TextBox)
                        Dim txtSUFigMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtSUFigMT"), TextBox)
                        Dim txtShoreReceive As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceive"), TextBox)
                        Dim txtShoreReceiveMT As TextBox = CType(gridProduct.Rows(i).FindControl("txtShoreReceiveMT"), TextBox)
                        Dim txtPlus_Tank As TextBox = CType(gridProduct.Rows(i).FindControl("txtPlus_Tank"), TextBox)
                        If (clsFc.InsertLoad_Unload_Product(ViewState("EditBooking"), gridProduct.DataKeys(i).Values("Product_no"), txtBLFig.Text, txtBLFigMT.Text, txtLineBeforeFrom.Text, txtLineBeforeTo.Text, txtConnectDate.Text, txtConnectMLAFrom.Text, txtConnectMLATo.Text, lbStartStandardDate.Text, lbStartStandard.Text, txtStartActualDate.Text, txtStartActualTime.Text, lbStopStandardDate.Text, lbStopStandard.Text, txtStopActualDate.Text, txtStopActualTime.Text, txtSLFig.Text, txtSLFigMT.Text, txtLineafterFrom.Text, txtLineafterTo.Text, txtDisDate.Text, txtDisMLAFrom.Text, txtDisMLATo.Text, txtAPIShore.Text, txtAPIShip.Text, txtVisShore.Text, txtVisShip.Text, txtSUFig.Text, txtSUFigMT.Text, txtShoreReceive.Text, txtShoreReceiveMT.Text, txtPlus_Tank.Text, gridProduct.DataKeys(i).Values("Product_Index"), conn, tran) < 1) Then
                            condition = False
                            Exit For
                        End If
                    End If
                Next

                Dim dtDelay As DataTable = Session("Delay")
                For Each dr As DataRow In dtDelay.Rows
                    If (clsFc.InsertLoad_Unload_Delay(ViewState("EditBooking"), dr.Item("Date_From"), dr.Item("Date_To"), dr.Item("Time_From"), dr.Item("Time_To"), dr.Item("Cause_Delay"), dr.Item("Delay_Time"), dr.Item("Cause_Code"), conn, tran) < 1) Then
                        condition = False
                        Exit For
                    End If
                Next
                If (clsFc.InsertLoad_Unload_Addition(ViewState("EditBooking"), "0", "0", "0", "0", txtWater.Text, "0", txtDisposal.Text, txtBunker_FO.Text, txtBunker_DO.Text, "0", txtExcise.Text, txtNitrogen.Text, txtElectic.Text, "0", "00:00", "00:00", "", "", conn, tran) < 1) Then
                    condition = False
                End If
                For i As Integer = 0 To gridStock.Rows.Count - 1
                    Dim txtCount As TextBox = CType(gridStock.Rows(i).FindControl("txtCount"), TextBox)
                    Dim chk As CheckBox = CType(gridStock.Rows(i).FindControl("chkStock"), CheckBox)
                    Dim statusss As String = ""
                    If (chk.Checked) Then
                        statusss = "Y"
                    Else
                        statusss = "N"
                    End If
                    If (txtCount.Text = "") Then
                        txtCount.Text = "0"
                    End If
                    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), gridStock.DataKeys(i).Values("Stock_Code"), gridStock.DataKeys(i).Values("Grade"), gridStock.DataKeys(i).Values("Brand"), txtCount.Text, statusss, conn, tran) < 1) Then
                        condition = False
                    End If
                Next
                'Dim ds As DataSet = Session("_STOCK")
                'For Each drstock As DataRow In ds.Tables(0).Rows
                '    If (clsFc.InsertLoad_Unload_Addition_Stock(ViewState("EditBooking"), drstock.Item("Stock_Code"), drstock.Item("Grade"), drstock.Item("Brand"), drstock.Item("Count"), conn, tran) < 1) Then
                '        condition = False
                '    End If
                'Next
            Else
                condition = False
            End If
            'If (clsFc.UPDATELoad_Unload_Vessel_Status(ViewState("EditBooking"), "S", conn, tran) < 1) Then
            '    condition = False
            'End If
            If (clsFc.InsertAction_Operation(A_Code, ViewState("EditBooking"), "Input Data By", DateTime.Now.ToString("dd MMMM yyyy", New CultureInfo("en-US")), DateTime.Now.ToString("HH:mm"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Name"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name"), "", conn, tran) < 1) Then
                condition = False
            End If
            If (condition) Then
                clsDB.CommitTran(tran)
                LoadBOoking()
                If Not CBool(ViewState("Start")) Then
                    Dim str As String = ""
                    Dim dtBOoking As DataTable = clsGet.Get_BookingOneRecord(ViewState("EditBooking")).Tables(0)
                    Dim dtLogIn As DataTable = clsGet.Get_Booking_LogSheet_In(ViewState("EditBooking"))
                    Dim Berth As String = ""
                    If (dtLogIn.Rows.Count > 0) Then
                        Try
                            Berth = dtLogIn.Rows(0).Item("Berthing_Date") & " " & dtLogIn.Rows(0).Item("Berthing_TimeTo")
                        Catch ex As Exception

                        End Try

                    End If
                    str = GenBody("เริ่มดำเนินการขนถ่าย", ViewState("EditBooking"), dtBOoking.Rows(0).Item("MAgent_no") & "-" & dtBOoking.Rows(0).Item("MAgent_name"), dtBOoking.Rows(0).Item("Vehicle_no") & "-" & dtBOoking.Rows(0).Item("Vehicle_Text"), dtBOoking.Rows(0).Item("Date_From") & "-" & dtBOoking.Rows(0).Item("Date_To"), Berth, start, "", "")
                    SendMail(ViewState("EditBooking"), "CUSTOMER", str)
                    ViewState("Start") = True
                End If
                ViewState("Load") = "Not"
                Timer1_Tick(sender, e)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('บันทึกข้อมูลสำเร็จ');", True)
            Else
                clsDB.RollBackTran(tran)
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เกิดความผิดพลาดในการบันทึก');", True)
            End If
            Application.UnLock()
            conn.Dispose()
        End If

    End Sub

    Private Sub btnReject_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReject.Click
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " document.getElementById('ctl00_contentplaceholder1_CancelPopup').src = '../FormPopup/Cancel_popup.aspx?Type=REJECT';", True)
        ModalPopupExtender7.Show()
    End Sub

    Private Sub btnRejectOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRejectOK.Click
        Dim conn As New System.Data.SqlClient.SqlConnection(connString)
        Dim clsDB As New ClassDatabase
        Dim clsFc As New ClassFunction
        Dim condition As Boolean = True
        Dim tran As System.Data.SqlClient.SqlTransaction = Nothing
        Dim User_Modify As String = CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name")
        Application.Lock()
        conn.Open()
        Dim A_Code As String = clsDB.GeneratorID(conn, "Action_Operation")
        tran = clsDB.BeginTran(conn)

        If (clsFc.UPDATELoad_Unload_Vessel_Status(ViewState("EditBooking"), "R", conn, tran) < 1) Then
            condition = False
        End If
        If (clsFc.InsertAction_Operation(A_Code, ViewState("EditBooking"), "Reject Data By", DateTime.Now.ToString("dd MMMM yyyy", New CultureInfo("en-US")), DateTime.Now.ToString("HH:mm"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("Name"), CType(Session("UserData"), DataSet).Tables(0).Rows(0).Item("User_name"), Session("Cancel_Description") & "", conn, tran) < 1) Then
            condition = False
        End If
        If (condition) Then
            clsDB.CommitTran(tran)
            Session("Cancel_Description") = Nothing
            LoadBOoking()
            ViewState("Load") = "Not"
            Timer1_Tick(sender, e)
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('บันทึกข้อมูลสำเร็จ');", True)
        Else
            clsDB.RollBackTran(tran)
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('เกิดความผิดพลาดในการบันทึก');", True)
        End If
        Application.UnLock()
        conn.Dispose()
    End Sub

    Public Sub GenDateLiteral()
        Dim HTML As String = ""
        Dim dt As DataTable = clsGet.Get_Booking_ProductOperation(ViewState("EditBooking"))
        Dim dtproduct As DataTable = clsGet.Get_Load_Unload_Product_PTOL(ViewState("EditBooking"), "", "")
        HTML = "<table width='100%' border='0' cellpadding='0' cellspacing='1'>"
        HTML &= "<tr><td align='right' style='background-color: #2d9d1c;'><b><font class='White-Style' style='color:#ffffff'>Quantity Performance</font></b></td></tr>"
        If (lbDirection.Text = "LOADING") Then
            HTML &= "<tr>"
            HTML &= "<td align='center'>"
            HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>Qty(M<sup>3</sup>)</font></td>"
            For Each dr As DataRow In dt.Rows
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'B/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>1.B/L fig.</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BL"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'S/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>2.S/L fig.(Load Port)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SL"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'Diff Load Quan(1&2)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>3.Diff load quan(1&2)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            '% Diff (LOAD)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>4.% Diff(Load)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            HTML &= "</table></td>"
            HTML &= "</tr>"

            'MT
            HTML &= "<tr>"
            HTML &= "<td align='center'><hr /></td></tr>"

            HTML &= "<tr>"
            HTML &= "<td align='center'>"
            HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>Qty(MT)</font></td>"
            For Each dr As DataRow In dt.Rows
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'B/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>1.B/L fig.</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BLMT"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'S/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>2.S/L fig.(Load Port)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SLMT"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'Diff Load Quan(1&2)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>3.Diff load quan(1&2)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))).ToString("###########0.000"), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))).ToString("###########0.000"), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            '% Diff (LOAD)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>4.% Diff(Load)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            HTML &= "</table></td>"
            HTML &= "</tr>"
        Else
            'UNLOADING
            HTML &= "<tr>"
            HTML &= "<td align='center'>"
            HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>Qty(M<sup>3</sup>)</font></td>"
            For Each dr As DataRow In dt.Rows
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'B/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>1.B/L fig.</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BL"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'S/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>2.S/L fig.(Load Port)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SL"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'S/U fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>3.S/U fig.(Dis. Port)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SU"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'Shore Recieve fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>4.Shore Recieve fig.</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_ShoreRecieve"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'Diff Qty(Load Port & B/L)(2&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>5.Diff Qty(2&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            '%Diff Qty(Load Port & B/L)(2&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>6.%Diff Qty(2&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            'Diff Qty(Intrasit Loss)(3&2)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>7.Diff Qty(3&2)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_SL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            '%Diff Qty(Intrasit Loss)(3&2)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>8.%Diff Qty(3&2)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_SL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'Diff Qty(Disch.Port & B/L)(3&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>9.Diff Qty(3&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            '%Diff Qty(Disch.Port & B/L)(3&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>10.%Diff Qty(3&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            'Diff Qty(Shore & B/L)(4&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>11.Diff Qty(4&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieve")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            '%Diff Qty(Shore & B/L)(4&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>12.%Diff Qty(4&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieve")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            HTML &= "</table></td>"
            HTML &= "</tr>"

            'MT
            HTML &= "<tr>"
            HTML &= "<td align='center'><hr /></td></tr>"

            HTML &= "<tr>"
            HTML &= "<td align='center'>"
            HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>Qty(MT)</font></td>"
            For Each dr As DataRow In dt.Rows
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'B/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>1.B/L fig.</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BLMT"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'S/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>2.S/L fig.(Load Port)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SLMT"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"
            'S/U fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>3.S/U fig.(Dis. Port)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SUMT"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'Shore Recieve fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>4.Shore Recieve fig.</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_ShoreRecieveMT"), 3) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'Diff Qty(Load Port & B/L)(2&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>5.Diff Qty(2&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            '%Diff Qty(Load Port & B/L)(2&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>6.%Diff Qty(2&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            'Diff Qty(Intrasit Loss)(3&2)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>7.Diff Qty(3&2)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_SLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            '%Diff Qty(Intrasit Loss)(3&2)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>8.%Diff Qty(3&2)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_SLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            'Diff Qty(Disch.Port & B/L)(3&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>9.Diff Qty(3&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            '%Diff Qty(Disch.Port & B/L)(3&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>10.%Diff Qty(3&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"


            'Diff Qty(Shore & B/L)(4&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>11.Diff Qty(4&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieveMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))), 3) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))), 3) & ")</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            '%Diff Qty(Shore & B/L)(4&1)
            HTML &= "<tr>"
            HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>12.%Diff Qty(4&1)</font></td>"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieveMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    End If
                Next

            Next
            HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
            HTML &= "</tr>"

            HTML &= "</table></td>"
            HTML &= "</tr>"


        End If
        'API
        HTML &= "<tr><td align='right' style='background-color: #2d9d1c;'><b><font class='White-Style' style='color:#ffffff'>Quatity Performance</font></b></td></tr>"

        HTML &= "<tr>"
        HTML &= "<td align='center'>"
        HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>API</font></td>"
        For Each dr As DataRow In dt.Rows
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Shore
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Shore</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dx.Item("API_Shore") & "</font></td>"
                    Exit For
                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Ship
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Ship</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dx.Item("API_Ship") & "</font></td>"
                    Exit For
                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Diff
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Diff</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    Try
                        If (CDbl(dx.Item("API_Ship")) >= CDbl(dx.Item("API_Shore"))) Then
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(dx.Item("API_Ship")) - CDbl(dx.Item("API_Shore")), 2) & "%</font></td>"
                        Else
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(dx.Item("API_Ship")) - CDbl(dx.Item("API_Shore")), 2) & ")%</font></td>"
                        End If
                    Catch ex As Exception
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End Try

                    Exit For
                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"

        HTML &= "</table></td>"
        HTML &= "</tr>"
        'Viscosity
        HTML &= "<tr>"
        HTML &= "<td align='center'><hr /></td></tr>"

        HTML &= "<tr>"
        HTML &= "<td align='center'>"
        HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>Viscosity</font></td>"
        For Each dr As DataRow In dt.Rows
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Shore
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Shore</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dx.Item("VIS_Shore") & "</font></td>"
                    Exit For
                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Ship
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Ship</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dx.Item("VIS_Ship") & "</font></td>"
                    Exit For
                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Diff
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Diff</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    Try
                        If (CDbl(dx.Item("API_Ship")) >= CDbl(dx.Item("API_Shore"))) Then
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(dx.Item("VIS_Ship")) - CDbl(dx.Item("VIS_Shore")), 2) & "%</font></td>"
                        Else
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(dx.Item("VIS_Ship")) - CDbl(dx.Item("VIS_Shore")), 2) & ")%</font></td>"
                        End If
                    Catch ex As Exception
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End Try

                    Exit For
                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        HTML &= "</table></td>"
        HTML &= "</tr>"


        'Rate(M3/HR)
        Dim BookingWharf As String = clsGet.Get_BookingWharf(ViewState("EditBooking")).Rows(0).Item("BookingWharf") & ""
        HTML &= "<tr><td align='right' style='background-color: #2d9d1c;'><b><font class='White-Style' style='color:#ffffff'>Loading/Unloading Rate Performance</font></b></td></tr>"

        HTML &= "<tr>"
        HTML &= "<td align='center'>"
        HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>Rate(M<sup>3</sup>/Hr)</font></td>"
        For Each dr As DataRow In dt.Rows
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Time used(hrs)
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Time used(Hrs)</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "M3") Then
                        Try
                            Dim ts = DateDiff("n", dx.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StartActual_Time"), dx.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StopActual_Time"))
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & ts.ToString() & "min</font></td>"

                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Actual Rate
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Actual Rate</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "M3") Then
                        Try
                            Dim StartDateActual As String = dx.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StartActual_Date").ToString.Substring(6, 2)
                            Dim EndDateActual As String = dx.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StopActual_Date").ToString.Substring(6, 2)
                            Dim ts = DateDiff("n", StartDateActual & " " & dx.Item("LU_StartActual_Time"), EndDateActual & " " & dx.Item("LU_StopActual_Time"))
                            'ทำการลบค่า Delay ออก
                            'Dim dtDelay As DataTable = Session("Delay")
                            'If Not (dtDelay Is Nothing) Then
                            '    For Each dd As DataRow In dtDelay.Rows
                            '        Try
                            '            Dim startDate As String = dd.Item("Date_From").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_From").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_From").ToString.Substring(6, 2)
                            '            Dim EndDate As String = dd.Item("Date_To").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_To").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_To").ToString.Substring(6, 2)

                            '            If (CDate(startDate) = CDate(StartDateActual)) Then
                            '                'วันเดียวกัน
                            '                If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                            '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) >= CInt(dx.Item("LU_StartActual_Time").ToString().Split(":")(1))) Then
                            '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                            ts -= ts2
                            '                        ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                            If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                            '                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                                ts -= ts2
                            '                            End If
                            '                        End If
                            '                    End If
                            '                ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) > CInt(dx.Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                            '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                        ts -= ts2
                            '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                            '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                            ts -= ts2
                            '                        End If
                            '                    End If
                            '                End If
                            '            ElseIf (CDate(startDate) > CDate(StartDateActual)) Then
                            '                If (CDate(startDate) < CDate(EndDateActual)) Then
                            '                    'ตกในช่วง
                            '                    Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                    ts -= ts2
                            '                ElseIf (CDate(startDate) = CDate(EndDateActual)) Then
                            '                    'ตกในช่วง
                            '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                        ts -= ts2
                            '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                            '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                            ts -= ts2
                            '                        End If
                            '                    End If
                            '                End If

                            '            End If
                            '        Catch ex As Exception

                            '        End Try

                            '    Next
                            'End If
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & CInt(CDbl(dx.Item("LU_BL")) / ((CDbl(ts) / 60) / 24) / 24).ToString("00") & "</font></td>"

                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Standard Rate
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Standard Rate</font></td>"

        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "M3") Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & GetRate(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Diff
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Diff</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "M3") Then
                        Try
                            Dim ts = DateDiff("n", dx.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StartActual_Time"), dx.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StopActual_Time"))
                            Dim Actual As String = CInt(CDbl(dx.Item("LU_BL")) / ((CDbl(ts) / 60) / 24) / 24)
                            Dim Standard As String = GetRate(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility"))
                            If (Standard <= Actual) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & CInt(Actual) - CInt(Standard) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & CInt(Standard) - CInt(Actual) & ")</font></td>"
                            End If


                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        HTML &= "</table></td>"
        HTML &= "</tr>"

        HTML &= "<tr>"
        HTML &= "<td align='center'><hr /></td></tr>"
        'Rate (MT/Hr)
        HTML &= "<tr>"
        HTML &= "<td align='center'>"
        HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='center'><font class='White-Style' style='color:#000000'>Rate(MT/Hr)</font></td>"
        For Each dr As DataRow In dt.Rows
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Time used(hrs)
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Time used(Hrs)</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "MT") Then
                        Try
                            Dim ts = DateDiff("n", dx.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StartActual_Time"), dx.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StopActual_Time"))
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & ts.ToString() & "min</font></td>"

                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Actual Rate
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Actual Rate</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "MT") Then
                        Try
                            Dim StartDateActual As String = dx.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StartActual_Date").ToString.Substring(6, 2)
                            Dim EndDateActual As String = dx.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StopActual_Date").ToString.Substring(6, 2)
                            Dim ts = DateDiff("n", StartDateActual & " " & dx.Item("LU_StartActual_Time"), EndDateActual & " " & dx.Item("LU_StopActual_Time"))
                            'ทำการลบค่า Delay ออก
                            'Dim dtDelay As DataTable = Session("Delay")
                            'If Not (dtDelay Is Nothing) Then
                            '    For Each dd As DataRow In dtDelay.Rows
                            '        Try
                            '            Dim startDate As String = dd.Item("Date_From").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_From").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_From").ToString.Substring(6, 2)
                            '            Dim EndDate As String = dd.Item("Date_To").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_To").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_To").ToString.Substring(6, 2)

                            '            If (CDate(startDate) = CDate(StartDateActual)) Then
                            '                'วันเดียวกัน
                            '                If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                            '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) >= CInt(dx.Item("LU_StartActual_Time").ToString().Split(":")(1))) Then
                            '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                            ts -= ts2
                            '                        ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                            If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                            '                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                                ts -= ts2
                            '                            End If
                            '                        End If
                            '                    End If
                            '                ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) > CInt(dx.Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                            '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                        ts -= ts2
                            '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                            '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                            ts -= ts2
                            '                        End If
                            '                    End If
                            '                End If
                            '            ElseIf (CDate(startDate) > CDate(StartDateActual)) Then
                            '                If (CDate(startDate) < CDate(EndDateActual)) Then
                            '                    'ตกในช่วง
                            '                    Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                    ts -= ts2
                            '                ElseIf (CDate(startDate) = CDate(EndDateActual)) Then
                            '                    'ตกในช่วง
                            '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                        ts -= ts2
                            '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                            '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dx.Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                            '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                            '                            ts -= ts2
                            '                        End If
                            '                    End If
                            '                End If

                            '            End If
                            '        Catch ex As Exception

                            '        End Try

                            '    Next
                            'End If
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & CInt(CDbl(dx.Item("LU_BLMT")) / ((CDbl(ts) / 60) / 24) / 24) & "</font></td>"

                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Standard Rate
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Standard Rate</font></td>"

        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "MT") Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & GetRate(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) & "</font></td>"
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        'Diff
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Diff</font></td>"
        For Each dr As DataRow In dt.Rows
            For Each dx As DataRow In dtproduct.Rows
                If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                    If (GetUnit(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility")) = "MT") Then

                        Try
                            Dim ts = DateDiff("n", dx.Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StartActual_Time"), dx.Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dx.Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dx.Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dx.Item("LU_StopActual_Time"))
                            Dim Actual As String = CInt(CDbl(dx.Item("LU_BLMT")) / ((CDbl(ts) / 60) / 24) / 24)
                            Dim Standard As String = GetRate(dt, dr.Item("Product_Shore"), dr.Item("Group_no"), dr.Item("Product_Line"), dr.Item("Product_Event"), BookingWharf, dr.Item("Product_Facility"))
                            If (Standard <= Actual) Then
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & CInt(Actual) - CInt(Standard) & "</font></td>"
                            Else
                                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & CInt(Standard) - CInt(Actual) & ")</font></td>"
                            End If


                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try

                        Exit For
                    Else
                        HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                    End If

                End If
            Next

        Next
        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"
        HTML &= "</table></td>"
        HTML &= "</tr>"

        'Timing-Performance
        HTML &= "<tr><td align='right' style='background-color: #2d9d1c;'><b><font class='White-Style' style='color:#ffffff'>Timing-Performance</font></b></td></tr>"

        HTML &= "<tr>"
        HTML &= "<td align='center'>"
        HTML &= "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Standard time</font></td>"

        Dim dtLog_in As DataTable = clsGet.Get_Booking_LogSheet_In(ViewState("EditBooking"))
        Dim dtLoad_Vessel As DataTable = clsGet.Get_Load_Unload_Vessel(ViewState("EditBooking"))
        Try
            Dim Berthing_date As String = dtLog_in.Rows(0).Item("Berthing_Date")
            Try
                Dim TimeFrom As Int16 = CInt(dtLog_in.Rows(0).Item("Berthing_TimeFrom").ToString().Split(":")(0))
                Dim TimeTo As Int16 = CInt(dtLog_in.Rows(0).Item("Berthing_TimeTo").ToString().Split(":")(0))
                If (TimeFrom > TimeTo) Then
                    Berthing_date = CDate(ClassFunctionGetData.CDateT(Berthing_date)).AddDays(1).ToString("dd MMM yyyy")
                End If
            Catch ex As Exception

            End Try
            Dim ts = DateDiff("n", Berthing_date & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
            Dim Hour As String = ts \ 60
            Dim Minute As String = ts Mod 60

            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & CInt(Hour) & ":" & CInt(Minute).ToString("00") & "</font></td>"
        Catch ex As Exception
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
        End Try


        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"

        'Actual used
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Actual used</font></td>"

        Try
            Dim Berthing_date As String = dtLog_in.Rows(0).Item("Berthing_Date")
            Try
                Dim TimeFrom As Int16 = CInt(dtLog_in.Rows(0).Item("Berthing_TimeFrom").ToString().Split(":")(0))
                Dim TimeTo As Int16 = CInt(dtLog_in.Rows(0).Item("Berthing_TimeTo").ToString().Split(":")(0))
                If (TimeFrom > TimeTo) Then
                    Berthing_date = CDate(ClassFunctionGetData.CDateT(Berthing_date)).AddDays(1).ToString("dd MMM yyyy")
                End If
            Catch ex As Exception

            End Try
            Dim ts = DateDiff("n", Berthing_date & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))

            Dim Hour As String = ts \ 60
            Dim Minute As String = ts Mod 60

            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & CInt(Hour) & ":" & CInt(Minute).ToString("00") & "</font></td>"
        Catch ex As Exception
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
        End Try

        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"

        'Less/(More)
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>Less/(More)</font></td>"

        Try
            Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))
            Dim actual = ts
            ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
            If (ts >= actual) Then
                ts = ts - actual
                Dim Hour As String = ts \ 60
                Dim Minute As String = ts Mod 60
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & CInt(Hour) & ":" & CInt(Minute).ToString("00") & "</font></td>"
            Else
                ts = actual - ts
                Dim Hour As String = ts \ 60
                Dim Minute As String = ts Mod 60
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & CInt(Hour) & ":" & CInt(Minute).ToString("00") & ")</font></td>"
            End If

        Catch ex As Exception
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
        End Try


        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"

        '% Diff
        HTML &= "<tr>"
        HTML &= "<td style='width:140px;background-color: #def7d2;'align='left'><font class='White-Style' style='color:#000000'>% Diff</font></td>"

        Try
            Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))
            Dim actual = ts
            ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
            If (ts >= actual) Then
                Dim diff As String = FormatNumber(((ts - actual) / actual) * 100, 2)
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>" & diff & "%</font></td>"
            Else
                Dim diff As String = FormatNumber(((actual - ts) / actual) * 100, 2)
                HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'>(" & diff & ")%</font></td>"
            End If

        Catch ex As Exception
            HTML &= "<td style='width:80px;background-color: #c0e9ad;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
        End Try


        HTML &= "<td style='background-color: #c0e9ad;'>&nbsp;</td>"
        HTML &= "</tr>"

        HTML &= "</table></td>"
        HTML &= "</tr>"
        HTML &= "</table>"
        LiReport.Text = HTML
    End Sub

    Private Function GetRate(ByVal dtproduct As DataTable, ByVal Shore As String, ByVal Group_no As String, ByVal Line As String, ByVal LD As String, ByVal BookingWharf As String, ByVal Facility As String) As String
        Dim dt As DataTable = clsGet.Get_StandardTimeLiquid(Shore, Group_no, Line, LD, BookingWharf, Facility)
        ' dt.Rows(0).Item("Rate")
        If (dt.Rows.Count > 0) Then
            Dim LPG As Boolean = False
            Dim BUTANE As Boolean = False
            Dim LPG_BUTANE As Boolean = Facility
            For Each dr As DataRow In dtproduct.Rows
                If (dr.Item("Group_no") = "00031") Or (dr.Item("Group_no") = "00064") Then
                    LPG = True
                End If
                If (dr.Item("Group_no") = "00034") Then
                    BUTANE = True
                End If
            Next
            If (LPG) And (BUTANE) Then
                dt = clsGet.Get_StandardTimeLiquid(Shore, "00033", Line, LD, BookingWharf, Facility)
            End If
            Return dt.Rows(0).Item("Rate") & ""
        Else
            Return 0
        End If
    End Function

    Private Function GetUnit(ByVal dtproduct As DataTable, ByVal Shore As String, ByVal Group_no As String, ByVal Line As String, ByVal LD As String, ByVal BookingWharf As String, ByVal Facility As String) As String
        Dim dt As DataTable = clsGet.Get_StandardTimeLiquid(Shore, Group_no, Line, LD, BookingWharf, Facility)
        ' dt.Rows(0).Item("Rate")
        If (dt.Rows.Count > 0) Then
            Dim LPG As Boolean = False
            Dim BUTANE As Boolean = False
            Dim LPG_BUTANE As Boolean = Facility
            For Each dr As DataRow In dtproduct.Rows
                If (dr.Item("Group_no") = "00031") Or (dr.Item("Group_no") = "00064") Then
                    LPG = True
                End If
                If (dr.Item("Group_no") = "00034") Then
                    BUTANE = True
                End If
            Next
            If (LPG) And (BUTANE) Then
                dt = clsGet.Get_StandardTimeLiquid(Shore, "00033", Line, LD, BookingWharf, Facility)
            End If
            Return dt.Rows(0).Item("Unit") & ""
        Else
            Return 0
        End If
    End Function

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "M")
        End If
    End Sub

    Public Sub GetPTOL()
        Dim HTML As String = ""
        Dim dt As DataTable = clsGet.Get_Booking_ProductOperation(ViewState("EditBooking"))
        Dim dtproduct As DataTable = clsGet.Get_Load_Unload_Product_PTOL(ViewState("EditBooking"), "", "")
        HTML = "<table width='100%' border='0' cellpadding='0' cellspacing='1'>"
        HTML &= "<tr>"
        HTML &= "<td align='center' rowspan='2' style='background-color: #9aceff;'><b><font class='White-Style' style='color:#ffffff'>Quantities</font></b></td>"
        For Each dr As DataRow In dt.Rows
            HTML &= "<td colspan='2' style='width:180px;background-color: #9aceff;'><font class='White-Style' style='color:#000000'>" & dr.Item("Product_name") & "</font></td>"
        Next
        HTML &= "</tr>"
        HTML &= "<tr>"

        For Each dr As DataRow In dt.Rows
            HTML &= "<td style='background-color: #9aceff;'><font class='White-Style' style='color:#000000'>M<sup>3</sup></font></td>"
            HTML &= "<td style='background-color: #9aceff;'><font class='White-Style' style='color:#000000'>MT</font></td>"
        Next
        HTML &= "</tr>"

        Dim dtForReport As DataTable = CreateForReportService()
        Dim C As Integer = 1
        If (lbDirection.Text = "LOADING") Then

            'B/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>1.B/L fig.</font></td>"
            Dim dd As DataRow = dtForReport.NewRow()
            dd.Item("Quantity") = "1.B/L fig."
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BL"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("Value1_1") = FormatNumber(dx.Item("LU_BL"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("Value2_1") = FormatNumber(dx.Item("LU_BL"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("Value3_1") = FormatNumber(dx.Item("LU_BL"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("Value4_1") = FormatNumber(dx.Item("LU_BL"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BLMT"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("value1_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("value2_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("value3_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("value4_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        C += 1

                        Exit For
                    End If
                Next

            Next

            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"
            'S/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>2.S/L fig.(Load Port)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "2.S/L fig.(Load Port)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SL"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("Value1_1") = FormatNumber(dx.Item("LU_SL"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("Value2_1") = FormatNumber(dx.Item("LU_SL"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("Value3_1") = FormatNumber(dx.Item("LU_SL"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("Value4_1") = FormatNumber(dx.Item("LU_SL"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SLMT"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("value1_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("value2_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("value3_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("value4_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        C += 1

                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"
            'Diff Load Quan(1&2)
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>3.Diff load quan(1&2)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "3.Diff load quan(1&2)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"

                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")</font></td>"

                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3) & "</font></td>"

                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")</font></td>"

                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"
            '% Diff (LOAD)
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>4.% Diff(Load)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "4.% Diff(Load)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber(((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber(((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber(((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber(((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / dx.Item("LU_BL")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"

                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber(((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber(((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber(((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber(((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / dx.Item("LU_BL")) * 100, 2) & ")%"
                                End Select
                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"

                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber(((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber(((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber(((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber(((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"

                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber(((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber(((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber(((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber(((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

        Else
            'UNLOADING

            'B/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>1.B/L fig.</font></td>"
            C = 1
            Dim dd As DataRow = dtForReport.NewRow()
            dd.Item("Quantity") = "1.B/L fig."
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BL"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("Value1_1") = FormatNumber(dx.Item("LU_BL"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("Value2_1") = FormatNumber(dx.Item("LU_BL"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("Value3_1") = FormatNumber(dx.Item("LU_BL"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("Value4_1") = FormatNumber(dx.Item("LU_BL"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_BLMT"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("value1_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("value2_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("value3_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("value4_2") = FormatNumber(dx.Item("LU_BLMT"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        C += 1

                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"
            'S/L fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>2.S/L fig.(Load Port)</font></td>"

            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "2.S/L fig.(Load Port)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SL"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("Value1_1") = FormatNumber(dx.Item("LU_SL"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("Value2_1") = FormatNumber(dx.Item("LU_SL"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("Value3_1") = FormatNumber(dx.Item("LU_SL"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("Value4_1") = FormatNumber(dx.Item("LU_SL"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SLMT"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("value1_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("value2_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("value3_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("value4_2") = FormatNumber(dx.Item("LU_SLMT"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        C += 1

                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"
            'S/U fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>3.S/U fig.(Dis. Port)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "3.S/U fig.(Dis. Port)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SU"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("Value1_1") = FormatNumber(dx.Item("LU_SU"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("Value2_1") = FormatNumber(dx.Item("LU_SU"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("Value3_1") = FormatNumber(dx.Item("LU_SU"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("Value4_1") = FormatNumber(dx.Item("LU_SU"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_SUMT"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("value1_2") = FormatNumber(dx.Item("LU_SUMT"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("value2_2") = FormatNumber(dx.Item("LU_SUMT"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("value3_2") = FormatNumber(dx.Item("LU_SUMT"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("value4_2") = FormatNumber(dx.Item("LU_SUMT"), 3)
                            End Select

                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '4.Shore Recieve fig.
            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>4.Shore Recieve fig.</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "4.Shore Recieve fig."
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_ShoreRecieve"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("Value1_1") = FormatNumber(dx.Item("LU_ShoreRecieve"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("Value2_1") = FormatNumber(dx.Item("LU_ShoreRecieve"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("Value3_1") = FormatNumber(dx.Item("LU_ShoreRecieve"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("Value4_1") = FormatNumber(dx.Item("LU_ShoreRecieve"), 3)
                            End Select
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        Try
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(dx.Item("LU_ShoreRecieveMT"), 3) & "</font></td>"
                            Select Case (C)
                                Case 1
                                    dd.Item("Product_name1") = dr.Item("Product_name")
                                    dd.Item("value1_2") = FormatNumber(dx.Item("LU_ShoreRecieveMT"), 3)
                                Case 2
                                    dd.Item("Product_name2") = dr.Item("Product_name")
                                    dd.Item("value2_2") = FormatNumber(dx.Item("LU_ShoreRecieveMT"), 3)
                                Case 3
                                    dd.Item("Product_name3") = dr.Item("Product_name")
                                    dd.Item("value3_2") = FormatNumber(dx.Item("LU_ShoreRecieveMT"), 3)
                                Case 4
                                    dd.Item("Product_name4") = dr.Item("Product_name")
                                    dd.Item("value4_2") = FormatNumber(dx.Item("LU_ShoreRecieveMT"), 3)
                            End Select

                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>&nbsp;</font></td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '5.Diff Qty(2&1)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>5.Diff Qty(2&1)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "5.Diff Qty(2&1)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"
            '6.%Diff Qty(2&1)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>6.%Diff Qty(2&1)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "6.%Diff Qty(2&1)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SL")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SLMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '7.Diff Qty(3&2)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>7.Diff Qty(3&2)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "7.Diff Qty(3&2)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_SL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber((CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_SLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber((CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '8.%Diff Qty(3&2)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>8.%Diff Qty(3&2)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "8.%Diff Qty(3&2)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_SL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_SL"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_SL")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_SLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_SLMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_SLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_SLMT")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '9.Diff Qty(3&1)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>9.Diff Qty(3&1)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "9.Diff Qty(3&1)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber((CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber((CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '10.%Diff Qty(3&1)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>10.%Diff Qty(3&1)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "10.%Diff Qty(3&1)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_SU")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_SU")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_SU"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_SUMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_SUMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_SUMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '11.Diff Qty(4&1)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>11.Diff Qty(4&1)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "11.Diff Qty(4&1)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieve")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber((CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieveMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber((CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))), 3) & "</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber((CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))), 3)
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))), 3) & ")</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))), 3) & ")"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))), 3) & ")"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))), 3) & ")"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber((CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))), 3) & ")"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

            '12.%Diff Qty(4&1)

            HTML &= "<tr>"
            HTML &= "<td style='width:180px;background-color: #9aceff;'align='left'><font class='White-Style' style='color:#000000'>12.%Diff Qty(4&1)</font></td>"
            C = 1
            dd = dtForReport.NewRow()
            dd.Item("Quantity") = "12.%Diff Qty(4&1)"
            For Each dr As DataRow In dt.Rows
                For Each dx As DataRow In dtproduct.Rows
                    If (dr.Item("BP_Code") = dx.Item("BP_Code")) Then
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieve")) >= CDbl(dx.Item("LU_BL"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieve")) - CDbl(dx.Item("LU_BL"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("Value1_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("Value2_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("Value3_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("Value4_1") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BL")) - CDbl(dx.Item("LU_ShoreRecieve"))) / CDbl(dx.Item("LU_BL")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        Try
                            If (CDbl(dx.Item("LU_ShoreRecieveMT")) >= CDbl(dx.Item("LU_BLMT"))) Then
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>" & FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = FormatNumber(CDbl(CDbl(dx.Item("LU_ShoreRecieveMT")) - CDbl(dx.Item("LU_BLMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & "%"
                                End Select
                            Else
                                HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'>(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%</font></td>"
                                Select Case (C)
                                    Case 1
                                        dd.Item("Product_name1") = dr.Item("Product_name")
                                        dd.Item("value1_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 2
                                        dd.Item("Product_name2") = dr.Item("Product_name")
                                        dd.Item("value2_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 3
                                        dd.Item("Product_name3") = dr.Item("Product_name")
                                        dd.Item("value3_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                    Case 4
                                        dd.Item("Product_name4") = dr.Item("Product_name")
                                        dd.Item("value4_2") = "(" & FormatNumber(CDbl(CDbl(dx.Item("LU_BLMT")) - CDbl(dx.Item("LU_ShoreRecieveMT"))) / CDbl(dx.Item("LU_BLMT")) * 100, 2) & ")%"
                                End Select

                            End If
                        Catch ex As Exception
                            HTML &= "<td style='width:80px;background-color: #def7d2;'><font class='White-Style' style='color:#000000'></font>&nbsp;</td>"
                        End Try
                        C += 1
                        Exit For
                    End If
                Next

            Next
            dtForReport.Rows.Add(dd)
            dtForReport.AcceptChanges()
            HTML &= "<td>&nbsp;</td>"
            HTML &= "</tr>"

        End If
        HTML &= "</table>"
        ViewState("reportService") = dtForReport
        LiProduct.Text = HTML


        Dim dtLog_in As DataTable = clsGet.Get_Booking_LogSheet_In(ViewState("EditBooking"))
        Dim dtLoad_Vessel As DataTable = clsGet.Get_Load_Unload_Vessel(ViewState("EditBooking"))
        Try
            Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
            Dim Hour As String = ts \ 60
            Dim Minute As String = ts Mod 60
            lbSTD.Text = CInt(Hour) & ":" & CInt(Minute).ToString("00")

        Catch ex As Exception
            lbSTD.Text = ""
        End Try


        'Actual used
        Try
            Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))
            Dim Hour As String = ts \ 60
            Dim Minute As String = ts Mod 60
            lbActual.Text = CInt(Hour) & ":" & CInt(Minute).ToString("00")

        Catch ex As Exception
            lbActual.Text = ""
        End Try

        'Less/(More)
        Try
            Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))
            Dim actual = ts
            ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
            If (ts >= actual) Then
                ts = ts - actual
                Dim Hour As String = ts \ 60
                Dim Minute As String = ts Mod 60
                lbLess.Text = CInt(Hour) & ":" & CInt(Minute).ToString("00")
            Else
                ts = actual - ts
                Dim Hour As String = ts \ 60
                Dim Minute As String = ts Mod 60
                lbLess.Text = "(" & CInt(Hour) & ":" & CInt(Minute).ToString("00") & ")"
            End If

        Catch ex As Exception
            lbLess.Text = ""
        End Try
    End Sub

    Private Sub TabShip_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabShip.ActiveTabChanged
        If (TabShip.ActiveTabIndex = "1") Then
            lbThird.Text = txtThirdParty.Text
            lbVessel_Berth.Text = lbBerthedDate.Text & " " & lbBerthed.Text
            lbVessel_Depart.Text = txtDepartActualDate.Text & " " & txtDepartAutualTime.Text
            lbWharfNo.Text = lbWharf.Text
            lbAttention.Text = lbShore.Text
            lbDepartDatereport.Text = txtDepartActualDate.Text
        End If
    End Sub

    Private Sub btnPrintShip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintShip.Click
        Dim service As New _ReportingService.Report

        Dim optWindow As String = "left=0,top=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no"
        Dim Orientation As Boolean = True
        Dim ReportName As String = String.Empty
        Dim reportDataSource As String = String.Empty
        Dim paraName As String = String.Empty
        Dim paraValue As String = String.Empty
        Dim reportType As String = String.Empty
        Dim urlDisplay As String = String.Empty
        Dim dsReport As New DataSet
        Dim dtVessel As DataTable = GetValue_Load(ViewState("EditBooking"))
        dsReport.Tables.Add(dtVessel)
        dsReport.AcceptChanges()
        dsReport.AcceptChanges()
        ReportName = "Ship_Loading_Performance_Control.rdlc"
        ' dsReport = New DataSet
        reportDataSource = "Ship_Performance_Load_Unload"
        paraName = "No;Tug_Before;Tug_After;Disposal;BunkerFO;BunkerDO;Water;Excise;Nitrogen;Crane"
        paraValue = lbNo.Text & ";" & lbTugBefore.Text & ";" & lbTugAfter.Text & ";" & txtDisposal.Text & ";" & txtBunker_FO.Text & ";" & txtBunker_DO.Text & ";" & txtWater.Text & ";" & txtExcise.Text & ";" & txtNitrogen.Text & ";" & txtElectic.Text
        Orientation = True
        reportType = "pdf"

        urlDisplay = service.CreateReporting(dsReport, reportDataSource, reportType, ReportName, paraName, paraValue, Orientation, "")

        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "window.open('" + urlDisplay + "','_blank','" + optWindow + "');", True)
    End Sub

    Private Function GetValue_Load(ByVal Booking_no As String) As DataTable

        Dim dt_Color As DataTable = clsGet.Get_Load_Unload_Addition_Stock(Booking_no).Tables(0)
        Dim CountColor As Integer = dt_Color.Rows.Count
        Dim dt_Product As DataTable = clsGet.Get_Booking_ProductOperation(Booking_no)
        Dim CountProduct As Integer = dt_Product.Rows.Count
        Dim Product_name As String = ""
        For Each dp As DataRow In dt_Product.Rows
            If Product_name = "" Then
                Product_name = dp.Item("Product_name")
            Else
                Product_name &= "," & dp.Item("Product_name")
            End If
        Next
        Dim dt_Delay As DataTable = clsGet.Get_Load_Unload_Delay(Booking_no)
        Dim COuntDelay As Integer = dt_Delay.Rows.Count
        Dim CountLoop As Integer = 0
        If (CountColor > CountLoop) Then
            CountLoop = CountColor
        End If
        If (CountProduct > CountLoop) Then
            CountLoop = CountProduct
        End If
        If (COuntDelay > CountProduct) Then
            CountLoop = COuntDelay
        End If

        Dim dtVessel As DataTable = CreateLoad_Unload_Vessel()
        Dim C_loop As Integer = 4
        If (lbDirection.Text <> "LOADING") Then
            C_loop = 12
        End If
        If (CountProduct > 0) Then
            For x As Integer = 0 To CountLoop - 1
                For i As Integer = 1 To C_loop
                    Dim dr As DataRow = dtVessel.NewRow()
                    dr.Item("Booking_no") = Booking_no

                    Dim dt As DataTable = clsGet.Get_Booking_LogSheet_In(ViewState("EditBooking"))
                    If (dt.Rows.Count = 1) Then
                        dr.Item("Vessel_Arrived") = ConvertDate(dt.Rows(0).Item("Anchor_Date")) & " " & dt.Rows(0).Item("Anchor_Time")
                        dr.Item("Estimate_NOR") = ConvertDate(dt.Rows(0).Item("Anchor_Date")) & " " & dt.Rows(0).Item("Anchor_Time")
                        dr.Item("POB") = ConvertDate(dt.Rows(0).Item("POB_Date")) & " " & dt.Rows(0).Item("POB_Time")
                        dr.Item("NOR_accepted") = ConvertDate(dt.Rows(0).Item("Berthing_Date")) & " " & dt.Rows(0).Item("Berthing_TimeTo")
                        dr.Item("Firstline") = ConvertDate(dt.Rows(0).Item("Berthing_Date")) & " " & dt.Rows(0).Item("Berthing_TimeFrom")
                        dr.Item("Berthed_Standard") = ConvertDate(dt.Rows(0).Item("Berthing_Date")) & " " & dt.Rows(0).Item("Berthing_TimeTo")
                        dr.Item("Berthed") = ConvertDate(dt.Rows(0).Item("Berthing_Date")) & " " & dt.Rows(0).Item("Berthing_TimeTo")
                    Else

                    End If
                    dt = clsGet.Get_Load_Unload_Vessel(ViewState("EditBooking"))
                    If (dt.Rows.Count > 0) Then
                        dr.Item("Third_payty") = dt.Rows(0).Item("Third_Party") & ""
                        dr.Item("Concern") = dt.Rows(0).Item("Concern") & ""
                        dr.Item("Tank_Before") = dt.Rows(0).Item("Tank_From") & "-" & dt.Rows(0).Item("Tank_To")
                        dr.Item("Figure_Before") = dt.Rows(0).Item("Figure")
                        dr.Item("Lab_Before") = dt.Rows(0).Item("Lab")
                        dr.Item("Sampling") = dt.Rows(0).Item("Sampling_From") & "-" & dt.Rows(0).Item("Sampling_To")
                        dr.Item("Lab_After") = dt.Rows(0).Item("Labafter")
                        dr.Item("Tank_After") = dt.Rows(0).Item("Tankafter_From") & "-" & dt.Rows(0).Item("Tankafter_To")
                        dr.Item("Figure_After") = dt.Rows(0).Item("Figureafter")
                        dr.Item("Document") = dt.Rows(0).Item("Document_Time")
                        dr.Item("Bunker_Truck") = dt.Rows(0).Item("Bunker_Point") & " Truck " & dt.Rows(0).Item("Bunker_Time")
                        dr.Item("Bunker_Standard") = dt.Rows(0).Item("Bunker_Standard_Date") & " " & dt.Rows(0).Item("Bunker_Standard_Time")
                        dr.Item("Bunker_Actual") = dt.Rows(0).Item("Bunker_Actual_Date") & " " & dt.Rows(0).Item("Bunker_Actual_Time")
                        dr.Item("Depart_Standard") = dt.Rows(0).Item("Depart_Standard_Date") & " " & dt.Rows(0).Item("Depart_Standard_Time")
                        dr.Item("Depart_Actual") = dt.Rows(0).Item("Depart_Actual_Date") & " " & dt.Rows(0).Item("Depart_Actual_Time")
                        dr.Item("NOR_Tender") = dt.Rows(0).Item("NOR_Date") & " " & dt.Rows(0).Item("NOR_Time")
                    Else

                    End If
                    dt = clsGet.Get_BookingOneRecord(Booking_no).Tables(0)
                    If (dt.Rows.Count > 0) Then
                        dr.Item("Vessel") = dt.Rows(0).Item("Vehicle_Text") & ""
                    End If

                    Dim row As Integer = 0
                    If (CountProduct > 0) Then
                        If ((x + 1) < CountProduct) Then
                            row = x
                        Else
                            row = (CountProduct - 1)
                        End If
                        Dim Facility As String = dt_Product.Rows(row).Item("Facility_Code")
                        Dim Shore As String = dt_Product.Rows(row).Item("Shore_Code")
                        Dim Line As String = dt_Product.Rows(row).Item("Line_Code")
                        Dim LD As String = dt_Product.Rows(row).Item("Product_Event")
                        Dim Group_no As String = dt_Product.Rows(row).Item("Group_no")
                        dt = clsGet.Get_Shore(Shore, "L")

                        dr.Item("Product") = Product_name
                        dr.Item("P_Index") = dt_Product.Rows(row).Item("indexproduct") & " " & dt_Product.Rows(row).Item("Product_name")
                        dr.Item("Product_name") = dt_Product.Rows(row).Item("Product_name") & ""
                        dr.Item("Shore") = dt.Rows(0).Item("Shore_Name") & ""
                        dr.Item("Target") = dt_Product.Rows(row).Item("Product_Amount") & " MT"
                        dt = clsGet.Get_BookingWharf(ViewState("EditBooking"))
                        If (dt.Rows.Count > 0) Then
                            dr.Item("Wharf") = dt.Rows(0).Item("Wharf") & ""
                            Dim BookingWharf As String = dt.Rows(0).Item("BookingWharf")

                            dt = clsGet.Get_Load_Unload_Product_PTOL(Booking_no, dt_Product.Rows(row).Item("Product_no"), dt_Product.Rows(row).Item("BP_Code"))
                            If (dt.Rows.Count > 0) Then
                                dr.Item("P_Code") = dt_Product.Rows(row).Item("Product_no") & row
                                dr.Item("Fill_Line") = dt_Product.Rows(row).Item("Line_Name") & ""
                                dr.Item("Fill") = dt.Rows(0).Item("LU_Fill_From") & "-" & dt.Rows(0).Item("LU_Fill_To")
                                dr.Item("Connect_MLA") = dt_Product.Rows(row).Item("Mla_Host")
                                dr.Item("Connect") = dt.Rows(0).Item("LU_Connect_Date") & " " & dt.Rows(0).Item("LU_Connect_From") & "-" & dt.Rows(0).Item("LU_Connect_To")
                                dr.Item("Start_Standard") = dt.Rows(0).Item("LU_StartStandard_Date") & " " & dt.Rows(0).Item("LU_StartStandard_Time")
                                dr.Item("Start_Actual") = dt.Rows(0).Item("LU_StartActual_Date") & " " & dt.Rows(0).Item("LU_StartActual_Time")
                                dr.Item("Stop_Standard") = dt.Rows(0).Item("LU_StopStandard_Date") & " " & dt.Rows(0).Item("LU_StopStandard_Time")
                                dr.Item("Stop_Actual") = dt.Rows(0).Item("LU_StopActual_Date") & " " & dt.Rows(0).Item("LU_StopActual_Time")
                                dr.Item("Fill_Line_After") = dt_Product.Rows(row).Item("Line_Name") & ""
                                dr.Item("Fill_After") = dt.Rows(0).Item("LU_Fillafter_From") & "-" & dt.Rows(0).Item("LU_Fillafter_To")
                                dr.Item("Disconnect_MLA") = dt_Product.Rows(row).Item("Mla_Host")
                                dr.Item("Disconnect") = dt.Rows(0).Item("LU_Disconnect_Date") & " " & dt.Rows(0).Item("LU_Disconnect_From") & "-" & dt.Rows(0).Item("LU_Disconnect_To")
                                dr.Item("BL_Fig") = dt.Rows(0).Item("LU_BL") & " M3 " & dt.Rows(0).Item("LU_BLMT") & " MT"
                                dr.Item("SL_Fig") = dt.Rows(0).Item("LU_SL") & " M3 " & dt.Rows(0).Item("LU_SLMT") & " MT"
                                dr.Item("Shore_P") = "API. " & dt.Rows(0).Item("API_Shore") & " Viscosity. " & dt.Rows(0).Item("Vis_Shore")
                                dr.Item("Ship_P") = "API. " & dt.Rows(0).Item("API_Ship") & " Viscosity. " & dt.Rows(0).Item("Vis_Ship")
                                dr.Item("Direction") = lbDirection.Text
                                If (lbDirection.Text = "LOADING") Then
                                    Select Case (i)
                                        Case 1
                                            dr.Item("Quantity") = "1.B/L fig."
                                            dr.Item("Quatity") = "Shore"
                                            dr.Item("Load_Unload") = "Time used(Hrs)"
                                            Try
                                                dr.Item("AmountM3") = FormatNumber(dt.Rows(0).Item("LU_BL"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                dr.Item("AmountMT") = FormatNumber(dt.Rows(0).Item("LU_BLMT"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    dr.Item("AmountM3_3") = ts.ToString() & " Min"

                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    dr.Item("AmountMT_3") = ts.ToString() & " Min"

                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                            dr.Item("AmountM3_2") = dt.Rows(0).Item("API_Shore")
                                            dr.Item("AmountMT_2") = dt.Rows(0).Item("Vis_Shore")
                                        Case 2
                                            dr.Item("Quantity") = "2.S/L fig.(Load Port)"
                                            dr.Item("Quatity") = "Ship"
                                            dr.Item("Load_Unload") = "Actual Rate"
                                            Try
                                                dr.Item("AmountM3") = FormatNumber(dt.Rows(0).Item("LU_SL"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                dr.Item("AmountMT") = FormatNumber(dt.Rows(0).Item("LU_SLMT"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try

                                            dr.Item("AmountM3_2") = dt.Rows(0).Item("API_Ship")
                                            dr.Item("AmountMT_2") = dt.Rows(0).Item("Vis_Ship")
                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim StartDateActual As String = dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2)
                                                    Dim EndDateActual As String = dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2)
                                                    Dim ts = DateDiff("n", StartDateActual & " " & dt.Rows(0).Item("LU_StartActual_Time"), EndDateActual & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    'ทำการลบค่า Delay ออก
                                                    'Dim dtDelay As DataTable = Session("Delay")
                                                    'If Not (dtDelay Is Nothing) Then
                                                    '    For Each dd As DataRow In dtDelay.Rows
                                                    '        Try
                                                    '            Dim startDate As String = dd.Item("Date_From").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_From").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_From").ToString.Substring(6, 2)
                                                    '            Dim EndDate As String = dd.Item("Date_To").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_To").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_To").ToString.Substring(6, 2)

                                                    '            If (CDate(startDate) = CDate(StartDateActual)) Then
                                                    '                'วันเดียวกัน
                                                    '                If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) >= CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(1))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                            If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                                ts -= ts2
                                                    '                            End If
                                                    '                        End If
                                                    '                    End If
                                                    '                ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) > CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                        ts -= ts2
                                                    '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        End If
                                                    '                    End If
                                                    '                End If
                                                    '            ElseIf (CDate(startDate) > CDate(StartDateActual)) Then
                                                    '                If (CDate(startDate) < CDate(EndDateActual)) Then
                                                    '                    'ตกในช่วง
                                                    '                    Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                    ts -= ts2
                                                    '                ElseIf (CDate(startDate) = CDate(EndDateActual)) Then
                                                    '                    'ตกในช่วง
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                        ts -= ts2
                                                    '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        End If
                                                    '                    End If
                                                    '                End If

                                                    '            End If
                                                    '        Catch ex As Exception

                                                    '        End Try

                                                    '    Next
                                                    'End If
                                                    dr.Item("AmountM3_3") = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / ((CDbl(ts) / 60) / 24) / 24)

                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else

                                                Try
                                                    Dim StartDateActual As String = dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2)
                                                    Dim EndDateActual As String = dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2)
                                                    Dim ts = DateDiff("n", StartDateActual & " " & dt.Rows(0).Item("LU_StartActual_Time"), EndDateActual & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    'ทำการลบค่า Delay ออก
                                                    'Dim dtDelay As DataTable = Session("Delay")
                                                    'If Not (dtDelay Is Nothing) Then
                                                    '    For Each dd As DataRow In dtDelay.Rows
                                                    '        Try
                                                    '            Dim startDate As String = dd.Item("Date_From").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_From").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_From").ToString.Substring(6, 2)
                                                    '            Dim EndDate As String = dd.Item("Date_To").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_To").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_To").ToString.Substring(6, 2)

                                                    '            If (CDate(startDate) = CDate(StartDateActual)) Then
                                                    '                'วันเดียวกัน
                                                    '                If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) >= CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(1))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                            If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                                ts -= ts2
                                                    '                            End If
                                                    '                        End If
                                                    '                    End If
                                                    '                ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) > CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                        ts -= ts2
                                                    '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        End If
                                                    '                    End If
                                                    '                End If
                                                    '            ElseIf (CDate(startDate) > CDate(StartDateActual)) Then
                                                    '                If (CDate(startDate) < CDate(EndDateActual)) Then
                                                    '                    'ตกในช่วง
                                                    '                    Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                    ts -= ts2
                                                    '                ElseIf (CDate(startDate) = CDate(EndDateActual)) Then
                                                    '                    'ตกในช่วง
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                        ts -= ts2
                                                    '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        End If
                                                    '                    End If
                                                    '                End If

                                                    '            End If
                                                    '        Catch ex As Exception

                                                    '        End Try

                                                    '    Next
                                                    'End If
                                                    dr.Item("AmountMT_3") = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / ((CDbl(ts) / 60) / 24) / 24)

                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 3
                                            dr.Item("Quantity") = "3.Diff load quan(1&2)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Standard Rate"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SL")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = (CDbl(dt.Rows(0).Item("LU_SL")) - CDbl(dt.Rows(0).Item("LU_BL"))).ToString("###########0.000")
                                                Else
                                                    dr.Item("AmountM3") = "(" & (CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_SL"))).ToString("###########0.000") & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SLMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = (CDbl(dt.Rows(0).Item("LU_SLMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))).ToString("###########0.000")
                                                Else
                                                    dr.Item("AmountMT") = "(" & (CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_SLMT"))).ToString("###########0.000") & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try
                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    dr.Item("AmountM3_3") = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    dr.Item("AmountMT_3") = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 4
                                            dr.Item("Quantity") = "4.% Diff(Load)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SL")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber(((CDbl(dt.Rows(0).Item("LU_SL")) - CDbl(dt.Rows(0).Item("LU_BL"))) / dt.Rows(0).Item("LU_BL")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber(((CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_SL"))) / dt.Rows(0).Item("LU_BL")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SLMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber(((CDbl(dt.Rows(0).Item("LU_SLMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))) / dt.Rows(0).Item("LU_BLMT")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber(((CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_SLMT"))) / dt.Rows(0).Item("LU_BLMT")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / ((CDbl(ts) / 60) / 24) / 24)
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / ((CDbl(ts) / 60) / 24) / 24)
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case Else
                                            dr.Item("Quantity") = "4.% Diff(Load"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SL")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber(((CDbl(dt.Rows(0).Item("LU_SL")) - CDbl(dt.Rows(0).Item("LU_BL"))) / dt.Rows(0).Item("LU_BL")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber(((CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_SL"))) / dt.Rows(0).Item("LU_BL")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SLMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber(((CDbl(dt.Rows(0).Item("LU_SLMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))) / dt.Rows(0).Item("LU_BLMT")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber(((CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_SLMT"))) / dt.Rows(0).Item("LU_BLMT")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try
                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                    End Select
                                Else
                                    'UNLOADING

                                    Select Case (i)
                                        Case 1
                                            dr.Item("Quantity") = "1.B/L fig."
                                            dr.Item("Quatity") = "Shore"
                                            dr.Item("Load_Unload") = "Time used(Hrs)"
                                            Try
                                                dr.Item("AmountM3") = FormatNumber(dt.Rows(0).Item("LU_BL"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                dr.Item("AmountMT") = FormatNumber(dt.Rows(0).Item("LU_BLMT"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    dr.Item("AmountM3_3") = ts.ToString() & " Min"

                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    dr.Item("AmountMT_3") = ts.ToString() & " Min"

                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                            dr.Item("AmountM3_2") = dt.Rows(0).Item("API_Shore")
                                            dr.Item("AmountMT_2") = dt.Rows(0).Item("Vis_Shore")
                                        Case 2
                                            dr.Item("Quantity") = "2.S/L fig.(Load Port)"
                                            dr.Item("Quatity") = "Ship"
                                            dr.Item("Load_Unload") = "Actual Rate"
                                            Try
                                                dr.Item("AmountM3") = FormatNumber(dt.Rows(0).Item("LU_SL"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                dr.Item("AmountMT") = FormatNumber(dt.Rows(0).Item("LU_SLMT"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try

                                            dr.Item("AmountM3_2") = dt.Rows(0).Item("API_Ship")
                                            dr.Item("AmountMT_2") = dt.Rows(0).Item("Vis_Ship")
                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim StartDateActual As String = dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2)
                                                    Dim EndDateActual As String = dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2)
                                                    Dim ts = DateDiff("n", StartDateActual & " " & dt.Rows(0).Item("LU_StartActual_Time"), EndDateActual & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    'ทำการลบค่า Delay ออก
                                                    'Dim dtDelay As DataTable = Session("Delay")
                                                    'If Not (dtDelay Is Nothing) Then
                                                    '    For Each dd As DataRow In dtDelay.Rows
                                                    '        Try
                                                    '            Dim startDate As String = dd.Item("Date_From").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_From").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_From").ToString.Substring(6, 2)
                                                    '            Dim EndDate As String = dd.Item("Date_To").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_To").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_To").ToString.Substring(6, 2)

                                                    '            If (CDate(startDate) = CDate(StartDateActual)) Then
                                                    '                'วันเดียวกัน
                                                    '                If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) >= CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(1))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                            If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                                ts -= ts2
                                                    '                            End If
                                                    '                        End If
                                                    '                    End If
                                                    '                ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) > CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                        ts -= ts2
                                                    '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        End If
                                                    '                    End If
                                                    '                End If
                                                    '            ElseIf (CDate(startDate) > CDate(StartDateActual)) Then
                                                    '                If (CDate(startDate) < CDate(EndDateActual)) Then
                                                    '                    'ตกในช่วง
                                                    '                    Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                    ts -= ts2
                                                    '                ElseIf (CDate(startDate) = CDate(EndDateActual)) Then
                                                    '                    'ตกในช่วง
                                                    '                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                        ts -= ts2
                                                    '                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                    '                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                    '                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                    '                            ts -= ts2
                                                    '                        End If
                                                    '                    End If
                                                    '                End If

                                                    '            End If
                                                    '        Catch ex As Exception

                                                    '        End Try

                                                    '    Next
                                                    'End If
                                                    dr.Item("AmountM3_3") = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))

                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else

                                                Try
                                                    Dim StartDateActual As String = dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2)
                                                    Dim EndDateActual As String = dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2)
                                                    Dim ts = DateDiff("n", StartDateActual & " " & dt.Rows(0).Item("LU_StartActual_Time"), EndDateActual & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    'ทำการลบค่า Delay ออก
                                                    Dim dtDelay As DataTable = Session("Delay")
                                                    If Not (dtDelay Is Nothing) Then
                                                        For Each dd As DataRow In dtDelay.Rows
                                                            Try
                                                                Dim startDate As String = dd.Item("Date_From").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_From").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_From").ToString.Substring(6, 2)
                                                                Dim EndDate As String = dd.Item("Date_To").ToString.Substring(0, 2) & " " & GetNameMonth(dd.Item("Date_To").ToString.Substring(3, 2)) & " " & "20" & dd.Item("Date_To").ToString.Substring(6, 2)

                                                                If (CDate(ClassFunctionGetData.CDateT(startDate)) = CDate(ClassFunctionGetData.CDateT(StartDateActual))) Then
                                                                    'วันเดียวกัน
                                                                    If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                                        If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) >= CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(1))) Then
                                                                            If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                                                ts -= ts2
                                                                            ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                                                If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                                                    Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                                                    ts -= ts2
                                                                                End If
                                                                            End If
                                                                        End If
                                                                    ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) > CInt(dt.Rows(0).Item("LU_StartActual_Time").ToString().Split(":")(0))) Then
                                                                        If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                                            ts -= ts2
                                                                        ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                                            If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                                                ts -= ts2
                                                                            End If
                                                                        End If
                                                                    End If
                                                                ElseIf (CDate(ClassFunctionGetData.CDateT(startDate)) > CDate(ClassFunctionGetData.CDateT(StartDateActual))) Then
                                                                    If (CDate(ClassFunctionGetData.CDateT(startDate)) < CDate(ClassFunctionGetData.CDateT(EndDateActual))) Then
                                                                        'ตกในช่วง
                                                                        Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                                        ts -= ts2
                                                                    ElseIf (CDate(ClassFunctionGetData.CDateT(startDate)) = CDate(ClassFunctionGetData.CDateT(EndDateActual))) Then
                                                                        'ตกในช่วง
                                                                        If (CInt(dd.Item("Time_From").ToString().Split(":")(0)) < CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                                            Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                                            ts -= ts2
                                                                        ElseIf (CInt(dd.Item("Time_From").ToString().Split(":")(0)) = CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(0))) Then
                                                                            If (CInt(dd.Item("Time_From").ToString().Split(":")(1)) <= CInt(dt.Rows(0).Item("LU_StopActual_Time").ToString().Split(":")(1))) Then
                                                                                Dim ts2 = DateDiff("n", startDate & " " & dd.Item("Time_From"), EndDate & " " & dd.Item("Time_To"))
                                                                                ts -= ts2
                                                                            End If
                                                                        End If
                                                                    End If

                                                                End If
                                                            Catch ex As Exception

                                                            End Try

                                                        Next
                                                    End If
                                                    dr.Item("AmountMT_3") = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))

                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 3
                                            dr.Item("Quantity") = "3.S/U fig."
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Standard Rate"
                                            Try
                                                dr.Item("AmountM3") = FormatNumber(dt.Rows(0).Item("LU_SU"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                dr.Item("AmountMT") = FormatNumber(dt.Rows(0).Item("LU_SUMT"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try

                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try
                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    dr.Item("AmountM3_3") = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    dr.Item("AmountMT_3") = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 4
                                            dr.Item("Quantity") = "4.Shore Recieve fig."
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                dr.Item("AmountM3") = FormatNumber(dt.Rows(0).Item("LU_ShoreRecieve"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                dr.Item("AmountMT") = FormatNumber(dt.Rows(0).Item("LU_ShoreRecieveMT"), 3)
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 5
                                            dr.Item("Quantity") = "5.Diff Qty(2&1)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SL")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber((CDbl(dt.Rows(0).Item("LU_SL")) - CDbl(dt.Rows(0).Item("LU_BL"))), 3)
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_SL"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SLMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber((CDbl(dt.Rows(0).Item("LU_SLMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))), 3)
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_SLMT"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 6
                                            dr.Item("Quantity") = "6.%Diff Qty(2&1)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SL")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SL")) - CDbl(dt.Rows(0).Item("LU_BL"))) / CDbl(dt.Rows(0).Item("LU_BL")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_SL"))) / CDbl(dt.Rows(0).Item("LU_BL")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SLMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SLMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))) / CDbl(dt.Rows(0).Item("LU_BLMT")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_SLMT"))) / CDbl(dt.Rows(0).Item("LU_BLMT")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 7
                                            dr.Item("Quantity") = "7.Diff Qty(3&2)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SU")) >= CDbl(dt.Rows(0).Item("LU_SL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber((CDbl(dt.Rows(0).Item("LU_SU")) - CDbl(dt.Rows(0).Item("LU_SL"))), 3)
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_SL")) - CDbl(dt.Rows(0).Item("LU_SU"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SUMT")) >= CDbl(dt.Rows(0).Item("LU_SLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber((CDbl(dt.Rows(0).Item("LU_SUMT")) - CDbl(dt.Rows(0).Item("LU_SLMT"))), 3)
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_SLMT")) - CDbl(dt.Rows(0).Item("LU_SUMT"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 8
                                            dr.Item("Quantity") = "8.%Diff Qty(3&2)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SU")) >= CDbl(dt.Rows(0).Item("LU_SL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SU")) - CDbl(dt.Rows(0).Item("LU_SL"))) / CDbl(dt.Rows(0).Item("LU_SL")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SL")) - CDbl(dt.Rows(0).Item("LU_SU"))) / CDbl(dt.Rows(0).Item("LU_SL")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SUMT")) >= CDbl(dt.Rows(0).Item("LU_SLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SUMT")) - CDbl(dt.Rows(0).Item("LU_SLMT"))) / CDbl(dt.Rows(0).Item("LU_SLMT")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SLMT")) - CDbl(dt.Rows(0).Item("LU_SUMT"))) / CDbl(dt.Rows(0).Item("LU_SLMT")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 9
                                            dr.Item("Quantity") = "9.Diff Qty(3&1)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SU")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber((CDbl(dt.Rows(0).Item("LU_SU")) - CDbl(dt.Rows(0).Item("LU_BL"))), 3)
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_SU"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SUMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber((CDbl(dt.Rows(0).Item("LU_SUMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))), 3)
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_SUMT"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 10
                                            dr.Item("Quantity") = "10.%Diff Qty(3&1)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SU")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SU")) - CDbl(dt.Rows(0).Item("LU_BL"))) / CDbl(dt.Rows(0).Item("LU_BL")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_SU"))) / CDbl(dt.Rows(0).Item("LU_BL")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_SUMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_SUMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))) / CDbl(dt.Rows(0).Item("LU_BLMT")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_SUMT"))) / CDbl(dt.Rows(0).Item("LU_BLMT")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 11
                                            dr.Item("Quantity") = "11.Diff Qty(4&1)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_ShoreRecieve")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber((CDbl(dt.Rows(0).Item("LU_ShoreRecieve")) - CDbl(dt.Rows(0).Item("LU_BL"))), 3)
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_ShoreRecieve"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_ShoreRecieveMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber((CDbl(dt.Rows(0).Item("LU_ShoreRecieveMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))), 3)
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber((CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_ShoreRecieveMT"))), 3) & ")"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                        Case 12
                                            dr.Item("Quantity") = "12.%Diff Qty(4&1)"
                                            dr.Item("Quatity") = "Diff"
                                            dr.Item("Load_Unload") = "Diff"
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_ShoreRecieve")) >= CDbl(dt.Rows(0).Item("LU_BL"))) Then
                                                    dr.Item("AmountM3") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_ShoreRecieve")) - CDbl(dt.Rows(0).Item("LU_BL"))) / CDbl(dt.Rows(0).Item("LU_BL")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountM3") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_BL")) - CDbl(dt.Rows(0).Item("LU_ShoreRecieve"))) / CDbl(dt.Rows(0).Item("LU_BL")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("LU_ShoreRecieveMT")) >= CDbl(dt.Rows(0).Item("LU_BLMT"))) Then
                                                    dr.Item("AmountMT") = FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_ShoreRecieveMT")) - CDbl(dt.Rows(0).Item("LU_BLMT"))) / CDbl(dt.Rows(0).Item("LU_BLMT")) * 100, 2) & "%"
                                                Else
                                                    dr.Item("AmountMT") = "(" & FormatNumber(CDbl(CDbl(dt.Rows(0).Item("LU_BLMT")) - CDbl(dt.Rows(0).Item("LU_ShoreRecieveMT"))) / CDbl(dt.Rows(0).Item("LU_BLMT")) * 100, 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("API_Ship")) >= CDbl(dt.Rows(0).Item("API_Shore"))) Then
                                                    dr.Item("AmountM3_2") = FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountM3_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("API_Ship")) - CDbl(dt.Rows(0).Item("API_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountM3_2") = ""
                                            End Try
                                            Try
                                                If (CDbl(dt.Rows(0).Item("Vis_Ship")) >= CDbl(dt.Rows(0).Item("Vis_Shore"))) Then
                                                    dr.Item("AmountMT_2") = FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & "%"
                                                Else
                                                    dr.Item("AmountMT_2") = "(" & FormatNumber(CDbl(dt.Rows(0).Item("Vis_Ship")) - CDbl(dt.Rows(0).Item("Vis_Shore")), 2) & ")%"
                                                End If
                                            Catch ex As Exception
                                                dr.Item("AmountMT_2") = ""
                                            End Try

                                            If (GetUnit(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility")) = "M3") Then
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BL")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountM3_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountM3_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If
                                                Catch ex As Exception
                                                    dr.Item("AmountM3_3") = ""
                                                End Try
                                            Else
                                                Try
                                                    Dim ts = DateDiff("n", dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StartActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StartActual_Time"), dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(3, 2)) & " " & "20" & dt.Rows(0).Item("LU_StopActual_Date").ToString.Substring(6, 2) & " " & dt.Rows(0).Item("LU_StopActual_Time"))
                                                    Dim Actual As String = CInt(CDbl(dt.Rows(0).Item("LU_BLMT")) / (CDbl(ts) / 24))
                                                    Dim Standard As String = GetRate(dt_Product, dt_Product.Rows(row).Item("Product_Shore"), dt_Product.Rows(row).Item("Group_no"), dt_Product.Rows(row).Item("Product_Line"), dt_Product.Rows(row).Item("Product_Event"), BookingWharf, dt_Product.Rows(row).Item("Product_Facility"))
                                                    If (Standard <= Actual) Then
                                                        dr.Item("AmountMT_3") = CInt(Actual) - CInt(Standard)
                                                    Else
                                                        dr.Item("AmountMT_3") = "(" & CInt(Standard) - CInt(Actual) & ")"
                                                    End If


                                                Catch ex As Exception
                                                    dr.Item("AmountMT_3") = ""
                                                End Try
                                            End If
                                    End Select
                                End If

                                Dim dtLog_in As DataTable = clsGet.Get_Booking_LogSheet_In(Booking_no)
                                Dim dtLoad_Vessel As DataTable = clsGet.Get_Load_Unload_Vessel(Booking_no)
                                Try
                                    Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
                                    Dim Hour As String = ts \ 60
                                    Dim Minute As String = ts Mod 60

                                    dr.Item("Standard") = CInt(Hour) & ":" & CInt(Minute).ToString("00")
                                Catch ex As Exception
                                    dr.Item("Standard") = ""
                                End Try

                                Try
                                    Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))

                                    Dim Hour As String = ts \ 60
                                    Dim Minute As String = ts Mod 60

                                    dr.Item("Actual") = CInt(Hour) & ":" & CInt(Minute).ToString("00")
                                Catch ex As Exception
                                    dr.Item("Actual") = ""
                                End Try
                                Try
                                    Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))
                                    Dim actual = ts
                                    ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
                                    If (ts >= actual) Then
                                        ts = ts - actual
                                        Dim Hour As String = ts \ 60
                                        Dim Minute As String = ts Mod 60
                                        dr.Item("Less") = CInt(Hour) & ":" & CInt(Minute).ToString("00")
                                    Else
                                        ts = actual - ts
                                        Dim Hour As String = ts \ 60
                                        Dim Minute As String = ts Mod 60
                                        dr.Item("Less") = "(" & CInt(Hour) & ":" & CInt(Minute).ToString("00") & ")"
                                    End If

                                Catch ex As Exception
                                    dr.Item("Less") = ""
                                End Try

                                Try
                                    Dim ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Actual_Time"))
                                    Dim actual = ts
                                    ts = DateDiff("n", dtLog_in.Rows(0).Item("Berthing_Date") & " " & dtLog_in.Rows(0).Item("Berthing_TimeTo"), dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(0, 2) & " " & GetNameMonth(dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(3, 2)) & " " & "20" & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Date").ToString.Substring(6, 2) & " " & dtLoad_Vessel.Rows(0).Item("Depart_Standard_Time"))
                                    If (ts >= actual) Then
                                        Dim diff As String = FormatNumber(((ts - actual) / actual) * 100, 2)
                                        dr.Item("Diff") = diff & "%"
                                    Else
                                        Dim diff As String = FormatNumber(((actual - ts) / actual) * 100, 2)
                                        dr.Item("Diff") = "(" & diff & ")%"
                                    End If

                                Catch ex As Exception
                                    dr.Item("Diff") = ""
                                End Try
                            End If
                        End If
                    Else

                    End If
                    row = 0
                    If (COuntDelay > 0) Then
                        If ((x + 1) < COuntDelay) Then
                            row = x
                        Else
                            row = (COuntDelay - 1)
                        End If
                        dr.Item("Delay_Time") = dt_Delay.Rows(row).Item("Delay_DateTime") & ""
                        dr.Item("Cause") = dt_Delay.Rows(row).Item("Cause_Delay") & ""
                        dr.Item("D_Time") = dt_Delay.Rows(row).Item("Delay_Time") & ""
                        dr.Item("D_Code") = row
                    Else
                        dr.Item("Delay_Time") = ""
                        dr.Item("Cause") = ""
                        dr.Item("D_Time") = ""
                        dr.Item("D_Code") = ""
                    End If

                    row = 0
                    If (CountColor > 0) Then
                        If ((x + 1) < CountColor) Then
                            row = x
                        Else
                            row = (CountColor - 1)
                        End If
                        dr.Item("Grade") = dt_Color.Rows(row).Item("Grade") & ""
                        dr.Item("Brand") = dt_Color.Rows(row).Item("Brand") & ""
                        dr.Item("Count") = dt_Color.Rows(row).Item("Count") & ""
                    Else
                        dr.Item("Grade") = ""
                        dr.Item("Brand") = ""
                        dr.Item("Count") = ""
                    End If

                    dtVessel.Rows.Add(dr)
                    dtVessel.AcceptChanges()
                Next
            Next
        End If
        Return dtVessel
    End Function

    Private Function CreateLoad_Unload_Vessel() As DataTable
        Dim dt As New DataTable
        dt.TableName = "Load_Unload_Vessel"
        dt.Columns.Add("Booking_no", GetType(String))
        dt.Columns.Add("Vessel", GetType(String))
        dt.Columns.Add("Direction", GetType(String))
        dt.Columns.Add("Wharf", GetType(String))
        dt.Columns.Add("Product", GetType(String))
        dt.Columns.Add("Third_payty", GetType(String))
        dt.Columns.Add("Shore", GetType(String))
        dt.Columns.Add("Vessel_Arrived", GetType(String))
        dt.Columns.Add("Estimate_NOR", GetType(String))
        dt.Columns.Add("POB", GetType(String))
        dt.Columns.Add("NOR_accepted", GetType(String))
        dt.Columns.Add("Firstline", GetType(String))
        dt.Columns.Add("Berthed_Standard", GetType(String))
        dt.Columns.Add("Berthed", GetType(String))
        dt.Columns.Add("NOR_Tender", GetType(String))
        dt.Columns.Add("Concern", GetType(String))
        dt.Columns.Add("Tank_Before", GetType(String))
        dt.Columns.Add("Figure_Before", GetType(String))
        dt.Columns.Add("Lab_Before", GetType(String))
        dt.Columns.Add("Sampling", GetType(String))
        dt.Columns.Add("Lab_After", GetType(String))
        dt.Columns.Add("Tank_After", GetType(String))
        dt.Columns.Add("Figure_After", GetType(String))
        dt.Columns.Add("Document", GetType(String))
        dt.Columns.Add("Bunker_Truck", GetType(String))
        dt.Columns.Add("Bunker_Standard", GetType(String))
        dt.Columns.Add("Bunker_Actual", GetType(String))
        dt.Columns.Add("Depart_Standard", GetType(String))
        dt.Columns.Add("Depart_Actual", GetType(String))
        dt.Columns.Add("P_Index", GetType(String))
        dt.Columns.Add("Target", GetType(String))
        dt.Columns.Add("Fill_Line", GetType(String))
        dt.Columns.Add("Fill", GetType(String))
        dt.Columns.Add("Connect_MLA", GetType(String))
        dt.Columns.Add("Connect", GetType(String))
        dt.Columns.Add("Start_Standard", GetType(String))
        dt.Columns.Add("Start_Actual", GetType(String))
        dt.Columns.Add("Stop_Standard", GetType(String))
        dt.Columns.Add("Stop_Actual", GetType(String))
        dt.Columns.Add("Fill_Line_After", GetType(String))
        dt.Columns.Add("Fill_After", GetType(String))
        dt.Columns.Add("Disconnect_MLA", GetType(String))
        dt.Columns.Add("Disconnect", GetType(String))
        dt.Columns.Add("BL_Fig", GetType(String))
        dt.Columns.Add("SL_Fig", GetType(String))
        dt.Columns.Add("Shore_P", GetType(String))
        dt.Columns.Add("Ship_P", GetType(String))
        dt.Columns.Add("Delay_Time", GetType(String))
        dt.Columns.Add("Cause", GetType(String))
        dt.Columns.Add("D_Time", GetType(String))
        dt.Columns.Add("D_Code", GetType(String))
        dt.Columns.Add("P_Code", GetType(String))

        dt.Columns.Add("Product_name", GetType(String))
        dt.Columns.Add("Quantity", GetType(String))
        dt.Columns.Add("Quatity", GetType(String))
        dt.Columns.Add("Load_Unload", GetType(String))
        dt.Columns.Add("AmountM3", GetType(String))
        dt.Columns.Add("AmountMT", GetType(String))
        dt.Columns.Add("AmountM3_2", GetType(String))
        dt.Columns.Add("AmountMT_2", GetType(String))
        dt.Columns.Add("AmountM3_3", GetType(String))
        dt.Columns.Add("AmountMT_3", GetType(String))
        dt.Columns.Add("Standard", GetType(String))
        dt.Columns.Add("Actual", GetType(String))
        dt.Columns.Add("Less", GetType(String))
        dt.Columns.Add("Diff", GetType(String))
        dt.Columns.Add("Grade", GetType(String))
        dt.Columns.Add("Brand", GetType(String))
        dt.Columns.Add("Count", GetType(String))
        dt.AcceptChanges()
        Return dt
    End Function

    Private Sub gridStock_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridStock.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim chk As CheckBox = CType(e.Row.FindControl("chkStock"), CheckBox)
            If (gridStock.DataKeys(e.Row.RowIndex).Values("Status") & "" = "N") Then
                chk.Checked = False
                e.Row.Cells(4).Text = "ไม่ได้ทำการเติม"
            Else
                chk.Checked = True
            End If
        End If
    End Sub

    Private Sub btnSearchVPS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchVPS.Click
        LoadBOoking()
        ViewState("Load") = "Not"
        Timer1_Tick(sender, e)
    End Sub

    Private Sub btnPrintService_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintService.Click
        If (txtT1.Text.Trim() = "") Then
            If (txtT2.Text.Trim() <> "") Or (txtT3.Text.Trim() <> "") Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรุณาทำการระบุหัวข้อใหม่ให้ถูกต้องตามลำดับ!!');", True)
                Exit Sub
            End If
        ElseIf (txtT2.Text.Trim() = "") Then
            If (txtT3.Text <> "") Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรุณาทำการระบุหัวข้อใหม่ให้ถูกต้องตามลำดับ!!');", True)
                Exit Sub
            End If
        End If

        Dim service As New _ReportingService.Report

        Dim optWindow As String = "left=0,top=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no"
        Dim Orientation As Boolean = True
        Dim ReportName As String = String.Empty
        Dim reportDataSource As String = String.Empty
        Dim paraName As String = String.Empty
        Dim paraValue As String = String.Empty
        Dim reportType As String = String.Empty
        Dim urlDisplay As String = String.Empty
        Dim dsReport As New DataSet
        Dim C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, T1, TC1, TV1, T2, TC2, TV2, T3, TV3, TC3 As String
        If (txtTimeSheet.Text.Trim() = "") Then
            C1 = "-"
        Else
            C1 = txtTimeSheet.Text
        End If
        If (txtUllageBefore.Text.Trim() = "") Then
            C2 = "-"
        Else
            C2 = txtUllageBefore.Text
        End If
        If (txtUllageAfter.Text.Trim() = "") Then
            C3 = "-"
        Else
            C3 = txtUllageAfter.Text
        End If
        If (txtCargotank.Text.Trim() = "") Then
            C4 = "-"
        Else
            C4 = txtCargotank.Text
        End If
        If (txtCargoSeal.Text.Trim() = "") Then
            C5 = "-"
        Else
            C5 = txtCargoSeal.Text
        End If
        If (txtLetter.Text.Trim() = "") Then
            C6 = "-"
        Else
            C6 = txtLetter.Text
        End If
        If (txtNotice.Text.Trim() = "") Then
            C7 = "-"
        Else
            C7 = txtNotice.Text
        End If
        If (txtBringht.Text.Trim() = "") Then
            C8 = "-"
        Else
            C8 = txtBringht.Text
        End If
        If (txtCer.Text.Trim() = "") Then
            C9 = "-"
        Else
            C9 = txtCer.Text
        End If
        If (txtPaper.Text.Trim() = "") Then
            C10 = "-"
        Else
            C10 = txtPaper.Text
        End If
        If (txtlocal.Text.Trim() = "") Then
            C11 = "-"
        Else
            C11 = txtlocal.Text
        End If
        If (txtSSSC.Text.Trim() = "") Then
            C12 = "-"
        Else
            C12 = txtSSSC.Text
        End If
        If (txtEnclosed.Text.Trim() = "") Then
            C13 = "-"
        Else
            C13 = txtEnclosed.Text
        End If
        If (txtBunkerServey.Text.Trim = "") Then
            C14 = "-"
        Else
            C14 = txtBunkerServey.Text
        End If
        If (txtDye.Text.Trim() = "") Then
            C15 = "-"
        Else
            C15 = txtDye.Text
        End If
        If (txtQuality.Text.Trim() = "") Then
            C16 = "-"
        Else
            C16 = txtQuality.Text
        End If
        If (txtNOR.Text.Trim() = "") Then
            C17 = "-"
        Else
            C17 = txtNOR.Text
        End If
        If (txtOther.Text.Trim() = "") Then
            C18 = "-"
        Else
            C18 = txtOther.Text
        End If
        If (txtDisposalCer.Text.Trim() = "") Then
            C19 = "-"
        Else
            C19 = txtDisposalCer.Text
        End If
        TV1 = ""
        T1 = ""
        TC1 = ""
        TV2 = ""
        T2 = ""
        TC2 = ""
        T3 = ""
        TC3 = ""
        TV3 = ""
        If (txtT1.Text.Trim() = "") Then
            If (txtT2.Text.Trim() = "") Then
                If (txtT3.Text.Trim() <> "") Then
                    T1 = txtT3.Text
                    TC1 = ":"
                    If (txtV3.Text.Trim() = "") Then
                        TV1 = "-"
                    Else
                        TV1 = txtV3.Text
                    End If
                End If
            Else
                T1 = txtT2.Text
                TC1 = ":"
                If (txtV2.Text.Trim() = "") Then
                    TV1 = "-"
                Else
                    TV1 = txtV2.Text
                End If
                If (txtT3.Text.Trim() <> "") Then
                    T2 = txtT3.Text
                    TC2 = ":"
                    If (txtV3.Text.Trim() = "") Then
                        TV2 = "-"
                    Else
                        TV2 = txtV3.Text
                    End If
                End If
            End If
        Else
            T1 = txtT1.Text
            TC1 = ":"
            If (txtV1.Text.Trim() = "") Then
                TV1 = "-"
            Else
                TV1 = txtV1.Text
            End If
            If (txtT2.Text.Trim() = "") Then
                If (txtT3.Text.Trim() <> "") Then
                    T2 = txtT3.Text
                    TC2 = ":"
                    If (txtV3.Text.Trim() = "") Then
                        TV2 = "-"
                    Else
                        TV2 = txtV3.Text
                    End If
                End If
            Else
                T2 = txtT2.Text
                TC2 = ":"
                If (txtV2.Text.Trim() = "") Then
                    TV2 = "-"
                Else
                    TV2 = txtV2.Text
                End If
                If (txtT3.Text.Trim() <> "") Then
                    T3 = txtT3.Text
                    TC3 = ":"
                    If (txtV3.Text.Trim() = "") Then
                        TV3 = "-"
                    Else
                        TV3 = txtV3.Text
                    End If
                End If
            End If
        End If

        Dim dt As DataTable = ViewState("reportService")
        dt.Columns.Add("T1", GetType(String))
        dt.Columns.Add("TC1", GetType(String))
        dt.Columns.Add("TV1", GetType(String))
        dt.Columns.Add("T2", GetType(String))
        dt.Columns.Add("TC2", GetType(String))
        dt.Columns.Add("TV2", GetType(String))
        dt.Columns.Add("T3", GetType(String))
        dt.Columns.Add("TC3", GetType(String))
        dt.Columns.Add("TV3", GetType(String))
        dt.AcceptChanges()
        If (dt.Rows.Count > 0) Then
            dt.Rows(0).Item("T1") = T1
            dt.Rows(0).Item("TC1") = TC1
            dt.Rows(0).Item("TV1") = TV1
            dt.Rows(0).Item("T2") = T2
            dt.Rows(0).Item("TC2") = TC2
            dt.Rows(0).Item("TV2") = TV2
            dt.Rows(0).Item("T3") = T3
            dt.Rows(0).Item("TC3") = TC3
            dt.Rows(0).Item("TV3") = TV3
            For i As Integer = 0 To gridProduct.Rows.Count - 1
                Select Case (i)
                    Case 0
                        dt.Rows(0).Item("Product_name1") = gridProduct.DataKeys(i).Values("Product_name")
                    Case 1
                        dt.Rows(0).Item("Product_name2") = gridProduct.DataKeys(i).Values("Product_name")
                    Case 2
                        dt.Rows(0).Item("Product_name3") = gridProduct.DataKeys(i).Values("Product_name")
                    Case 3
                        dt.Rows(0).Item("Product_name4") = gridProduct.DataKeys(i).Values("Product_name")
                End Select
            Next
            dt.AcceptChanges()
        Else
            Dim dr As DataRow = dt.NewRow
            dr.Item("T1") = T1
            dr.Item("TC1") = TC1
            dr.Item("TV1") = TV1
            dr.Item("T2") = T2
            dr.Item("TC2") = TC2
            dr.Item("TV2") = TV2
            dr.Item("T3") = T3
            dr.Item("TC3") = TC3
            dr.Item("TV3") = TV3
            dt.Rows.Add(dr)
            dt.AcceptChanges()
        End If
        dsReport.Tables.Add(dt)
        dsReport.AcceptChanges()

        ReportName = "Ship_Service_Report.rdlc"
        ' dsReport = New DataSet
        reportDataSource = "Ship_Service_Service"
        paraName = "NoID;DateShow;Atten;Com;Vessel;Wharf;Berth;Depart;Third;STD;Actual;Less;C1;C2;C3;C4;C5;C6;C7;C8;C9;C10;C11;C12;C13;C14;C15;C16;C17;C18;C19"

        paraValue = lbNo2.Text & ";" & lbDepartDatereport.Text & ";" & lbAttention.Text & ";" & lbCommodity.Text & ";" & lbVessel_Name.Text & ";" & lbWharfNo.Text & ";" & lbVessel_Berth.Text & ";" & lbVessel_Depart.Text & ";" & lbThird.Text & ";" & lbSTD.Text & ";" & lbActual.Text & ";" & lbLess.Text & ";" & C1 & ";" & C2 & ";" & C3 & ";" & C4 & ";" & C5 & ";" & C6 & ";" & C7 & ";" & C8 & ";" & C9 & ";" & C10 & ";" & C11 & ";" & C12 & ";" & C13 & ";" & C14 & ";" & C15 & ";" & C16 & ";" & C17 & ";" & C18 & ";" & C19


        Orientation = True
        reportType = "pdf"

        urlDisplay = service.CreateReporting(dsReport, reportDataSource, reportType, ReportName, paraName, paraValue, Orientation, "")

        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "window.open('" + urlDisplay + "','_blank','" + optWindow + "');", True)
    End Sub

    Private Function CreateForReportService() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("Quantity", GetType(String))
        dt.Columns.Add("Product_name1", GetType(String))
        dt.Columns.Add("Product_name2", GetType(String))
        dt.Columns.Add("Product_name3", GetType(String))
        dt.Columns.Add("Product_name4", GetType(String))
        dt.Columns.Add("Value1_1", GetType(String))
        dt.Columns.Add("Value1_2", GetType(String))
        dt.Columns.Add("Value2_1", GetType(String))
        dt.Columns.Add("Value2_2", GetType(String))
        dt.Columns.Add("Value3_1", GetType(String))
        dt.Columns.Add("Value3_2", GetType(String))
        dt.Columns.Add("Value4_1", GetType(String))
        dt.Columns.Add("Value4_2", GetType(String))

        Return dt
    End Function

    Private Function GenBody(ByVal str As String, ByVal booking_no As String, ByVal Agent As String, ByVal Vessel As String, ByVal Laycan As String, ByVal Berth As String, ByVal Start As String, ByVal _Stop As String, ByVal Depart As String) As String
        Dim HTML As String = ""
        HTML = "<table width='100%' border='0' cellpadding='2' cellspacing='1'>"
        HTML &= "<tr>"
        HTML &= "<td align='left'><font class='White-Style' font-weight:bold style='color:#000000'>" & str & "</font></td>"
        HTML &= "</tr>"
        HTML &= "</table>"

        HTML &= "<table width='100%' border='0' cellpadding='2' cellspacing='1'>"
        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Booking No. :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & booking_no & "</font></td>"
        HTML &= "</tr>"
        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Sold To :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & Agent & "</font></td>"
        HTML &= "</tr>"
        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Vessel :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & Vessel & "</font></td>"
        HTML &= "</tr>"
        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Lay Can\Lay Day :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & Laycan & "</font></td>"
        HTML &= "</tr>"

        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Berth :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & Berth & "</font></td>"
        HTML &= "</tr>"
        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Start S/U S/L :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & Start & "</font></td>"
        HTML &= "</tr>"
        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Stop S/U S/L :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & _Stop & "</font></td>"
        HTML &= "</tr>"
        HTML &= "<tr>"
        HTML &= "<td style='width:220px;' align='right'><font class='White-Style' style='color:#000000'>Departed :</font>&nbsp;</td>"
        HTML &= "<td align='left'><font class='White-Style' style='color:#000000'>" & Depart & "</font></td>"
        HTML &= "</tr>"
        HTML &= "</table>"
        Return HTML
    End Function

    Private Function SendMail(ByVal Booking As String, ByVal SEND As String, ByVal Body As String) As Boolean
        Dim role As String = ""
        If (SEND = "PTO") Then
            role = clsGet.Get_EmailForSend("'00012','00004','00013','00014'") & ";" & clsGet.Get_EmailForSendAgent(Booking)
        ElseIf (SEND = "MARKETING") Then
            role = clsGet.Get_EmailForSend("'00003','00004','00012','00013','00014'") & ";" & clsGet.Get_EmailForSendAgent(Booking)
        ElseIf (SEND = "CUSTOMER") Then
            role = clsGet.Get_EmailForSend("'00004'") & ";" & clsGet.Get_EmailForSendAgent(Booking)
        End If
        Dim test As String = clsFc.sendmail(role, "", "iPORT", Body, "")
        If (test <> "") Then
            Return True
        Else
            Return False
        End If
    End Function
End Class